rdna2spirv: the PS FRONT_FACE VGPR is 0xffffffff / 0 — all 345 game shaders that read it test it against integer 0 (SHADER-892) #40

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

@⁠Andretuta on GitHub · 2026-11-24 02:05 UTC · original
ubiquitarianism:old-pr/5237 → main · +56 −5 · 3 files · 3 commits · draft

Carried over from old PR 5237 by rafaelpssz in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/5237, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
rafaelpssz: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

SHADER-892 (claim); finding by @Vonsek.

The question

On RDNA2, the pixel shader's FRONT_FACE system VGPR holds 0xffffffff (front) / 0 (back) when SPI_BARYC_CNTL.FRONT_FACE_ALL_BITS = 1, and +1.0 / −1.0 when it is 0 (measured on gfx1036, #5123). Nobody knew which one the console driver programs. The translator wrote the float form.

The count (my own 1.0.2.1 copy, full corpus, counts only)

The FRONT_FACE VGPR is the one right after the SV_Position components the shader reads (the translator's own layout). I followed it from the entry to its first uses.

pixel shaders
declare SV_IsFrontFace 1,984
never read the VGPR 1,639
read it 345
… first use an integer compare against 0 345: 282 v_cmp_ne_u32_e32, 62 v_cmp_ne_u32_e64, 1 v_cmp_eq_u32_e32
… a float compare, bit op or anything else 0

+1.0 (0x3F800000) and −1.0 (0xBF800000) are both non-zero, so in the float form != 0 says "front" for every face. The game's code only works with the mask form, so the console programs FRONT_FACE_ALL_BITS = 1. With the old translation, all 345 shaders treated back faces as front faces.

The change

  • tools/rdna2spirv.py stores OpSelect %uint FrontFacing 0xffffffff 0 into the VGPR. Before, it stored the bitcast of OpSelect %float FrontFacing 1.0 -1.0. The layout comment says so too.
  • docs/design.md ("PS system inputs") records the form and the count.
  • tests/test_ps_front_face.py translates a hand-written PS that reads x/y of SV_Position and then tests the facing VGPR (v4) with v_cmp_ne_u32 vcc, 0, v4. It checks that the select stores 0xffffffff / 0 into v4 and that the float form is gone. It fails on the old code.

Tests

  • The new test fails on the old code and passes now. tests/test_shader_meta.py, test_docs_design_rows.py and test_docs_links.py pass.
  • python -m unittest discover -s tests/semantic: the only failures (3 failures, 2 errors) are test_loop_ballot_barrier, the same as on main (the known wave64-emulation regression, #4363).
  • Corpus regression set: 712 pixel shaders that declare SV_IsFrontFace and have a v_cmp* with an immediate 0 on the FRONT_FACE register number anywhere in the listing. This is a superset of the 345 that includes register reuse, used as a translation set, not as a count. All 712 translate and pass spirv-val, both on main and with this change.
  • GPU (by reviewers, both windings, culling off):
    • @Kev-Ball, RTX 3080 Ti, Linux: back faces read 1.0 with the parent, the old bug, and 0.0 with this PR. Front faces read 1.0 on both.
    • @CryingLaughing, RTX 4080, Windows, validation on: with this PR, front = v4 == 0xffffffff and back = v4 == 0. That matches a Vulkan FrontFacing reference shader byte for byte over 4,096 pixels.

Thanks

  • @Vonsek for the finding and the gfx1036 measurement (#5123).
  • @Kev-Ball and @CryingLaughing for the two-winding GPU draws that pin the fix on hardware.
  • @Kam471 for the Windows run.
  • @sovljanskii for the Apple M4 (MoltenVK) winding run, the third GPU vendor.
  • @kacper-serewis for the independent reproduction of the 345 and the review that made the doc precise about 1/0 vs all-bits.
  • @SweatierKey for the Linux CPU verification of the follow-up head.
  • @amarovndres and @Atomic258 for the Windows CPU runs (Atomic258's with the negative control).
  • @tunczzz for the RTX 5070 Ti run.
  • @carlos-seiffert: tested on RTX 2060.
  • @SquishyGithub: tested on RTX 3070 (Linux).
  • @morodirule: independent corpus recount.
  • @javdc: tested on Steam Deck.
  • @TG0000: tested on RX 6800.
  • @phudyka for the GTX 1080 run on Linux: the full GPU suite on this head merged onto main, compared with main alone.
**@⁠Andretuta** on GitHub · 2026-11-24 02:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/40) `ubiquitarianism:old-pr/5237` → `main` · +56 −5 · 3 files · 3 commits · draft > Carried over from **old PR 5237** by `rafaelpssz` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/5237`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `rafaelpssz`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): SHADER-892 ([claim](https://github.com/ItsNotRexed/Leonida/issues/5032#issuecomment-7095799876)); finding by `@Vonsek`. ### The question On RDNA2, the pixel shader's FRONT_FACE system VGPR holds 0xffffffff (front) / 0 (back) when `SPI_BARYC_CNTL.FRONT_FACE_ALL_BITS` = 1, and +1.0 / −1.0 when it is 0 (measured on gfx1036, `#5123`). Nobody knew which one the console driver programs. The translator wrote the float form. ### The count (my own 1.0.2.1 copy, full corpus, counts only) The FRONT_FACE VGPR is the one right after the `SV_Position` components the shader reads (the translator's own layout). I followed it from the entry to its first uses. | | pixel shaders | |---|---:| | declare `SV_IsFrontFace` | 1,984 | | never read the VGPR | 1,639 | | read it | **345** | | … first use an integer compare against **0** | **345**: 282 `v_cmp_ne_u32_e32`, 62 `v_cmp_ne_u32_e64`, 1 `v_cmp_eq_u32_e32` | | … a float compare, bit op or anything else | **0** | +1.0 (`0x3F800000`) and −1.0 (`0xBF800000`) are both non-zero, so in the float form `!= 0` says "front" for every face. The game's code only works with the mask form, so the console programs `FRONT_FACE_ALL_BITS` = 1. With the old translation, all 345 shaders treated back faces as front faces. ### The change - `tools/rdna2spirv.py` stores `OpSelect %uint FrontFacing 0xffffffff 0` into the VGPR. Before, it stored the bitcast of `OpSelect %float FrontFacing 1.0 -1.0`. The layout comment says so too. - `docs/design.md` ("PS system inputs") records the form and the count. - `tests/test_ps_front_face.py` translates a hand-written PS that reads x/y of `SV_Position` and then tests the facing VGPR (v4) with `v_cmp_ne_u32 vcc, 0, v4`. It checks that the select stores 0xffffffff / 0 into v4 and that the float form is gone. It fails on the old code. ### Tests - The new test fails on the old code and passes now. `tests/test_shader_meta.py`, `test_docs_design_rows.py` and `test_docs_links.py` pass. - `python -m unittest discover -s tests/semantic`: the only failures (3 failures, 2 errors) are `test_loop_ballot_barrier`, the same as on `main` (the known wave64-emulation regression, `#4363`). - Corpus regression set: 712 pixel shaders that declare `SV_IsFrontFace` and have a `v_cmp*` with an immediate 0 on the FRONT_FACE register number anywhere in the listing. This is a superset of the 345 that includes register reuse, used as a translation set, not as a count. All 712 translate and pass `spirv-val`, both on `main` and with this change. - **GPU (by reviewers, both windings, culling off):** - `@Kev-Ball`, RTX 3080 Ti, Linux: back faces read **1.0** with the parent, the old bug, and **0.0** with this PR. Front faces read 1.0 on both. - `@CryingLaughing`, RTX 4080, Windows, validation on: with this PR, front = `v4 == 0xffffffff` and back = `v4 == 0`. That matches a Vulkan `FrontFacing` reference shader byte for byte over 4,096 pixels. ### Thanks - `@Vonsek` for the finding and the gfx1036 measurement (`#5123`). - `@Kev-Ball` and `@CryingLaughing` for the two-winding GPU draws that pin the fix on hardware. - `@Kam471` for the Windows run. - `@sovljanskii` for the Apple M4 (MoltenVK) winding run, the third GPU vendor. - `@kacper-serewis` for the independent reproduction of the 345 and the review that made the doc precise about 1/0 vs all-bits. - `@SweatierKey` for the Linux CPU verification of the follow-up head. - `@amarovndres` and `@Atomic258` for the Windows CPU runs (Atomic258's with the negative control). - `@tunczzz` for the RTX 5070 Ti run. - `@carlos-seiffert`: tested on RTX 2060. - `@SquishyGithub`: tested on RTX 3070 (Linux). - `@morodirule`: independent corpus recount. - `@javdc`: tested on Steam Deck. - `@TG0000`: tested on RX 6800. - `@phudyka` for the GTX 1080 run on Linux: the full GPU suite on this head merged onto main, compared with main alone.
RDNA2's FRONT_FACE system VGPR is 0xffffffff (front) / 0 (back) with
SPI_BARYC_CNTL.FRONT_FACE_ALL_BITS = 1 and +1.0 / -1.0 without it (#5123);
which one the console programs wasn't known. Over the 1.0.2.1 corpus, 1,984
pixel shaders declare SV_IsFrontFace, 345 read the VGPR, and every first use
is an integer compare against 0 (282 v_cmp_ne_u32_e32, 62 v_cmp_ne_u32_e64,
1 v_cmp_eq_u32_e32) - no float compare, bit op or other use. +1.0 and -1.0
are both non-zero, so with the float form the translator wrote, all 345
saw every face as front. It now stores the mask form.

tests/test_ps_front_face.py translates a hand-written PS that tests the VGPR
the same way and checks the stored values (fails on the old code). The
712 corpus PS that compare the FRONT_FACE register translate and pass
spirv-val before and after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
From @kacper-serewis's review of #5237: an integer compare against 0 can't
tell 0xffffffff/0 from 1/0; the mask form is the other one the hardware
gives (#5123).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
One conflict, in docs/design.md, with no competing edit: the v_swap_b32 row was changed only on main (taken as
main has it) and the PS system inputs row only on this branch (kept).

On the merged tree: tests/test_ps_front_face.py, tests/test_docs_links.py and tests/test_design_contract_rows.py
pass. The translator suite runs 459 files and 6,046 tests; three files fail (test_exec_computed 2 failures,
test_image_atomics_guard 47, test_image_cube_store_glc 1 error) and fail identically on main 7e39a81ea alone.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:41:59 +00:00
Author
Owner

@⁠ImLele69 on GitHub · 2026-11-24 11:37 UTC · original

Tested on Linux, merged onto main 21625bca8 (PR head ecaaf14b9, merges cleanly).

GPU: NVIDIA GeForce RTX 2070 SUPER (Turing, subgroup 32), proprietary driver 620.70.06, Fedora 44, llvm-mc 22.1.8, SPIRV-Tools 2026.1.

Run This PR main alone
run_gpu_tests.py native 197/248 passed, 49 skipped 197/248 passed, 49 skipped
LEONIDA_W64_EMULATE=1 229/248 passed, 17 skipped 229/248 passed, 17 skipped
run_semantic_tests.py tests/semantic 465 files, 6108 tests, 0 files failed in 101 s with 16 jobs 465 files, 6108 tests, 0 files failed

No new GPU fixture; no change in the GPU results against main.

The only failures in both runs are the known cs_imgload_tfe / cs_imgload_d16_tfe pair (#31), as on main. No regressions.

AI-assisted: yes (Claude Code ran the build and tests on my machine; numbers are the runners' own output).

**@⁠ImLele69** on GitHub · 2026-11-24 11:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/40#issuecomment-7130332580) Tested on Linux, merged onto `main` `21625bca8` (PR head `ecaaf14b9`, merges cleanly). GPU: NVIDIA GeForce RTX 2070 SUPER (Turing, subgroup 32), proprietary driver 620.70.06, Fedora 44, llvm-mc 22.1.8, SPIRV-Tools 2026.1. | Run | This PR | `main` alone | |---|---|---| | `run_gpu_tests.py` native | 197/248 passed, 49 skipped | 197/248 passed, 49 skipped | | `LEONIDA_W64_EMULATE=1` | 229/248 passed, 17 skipped | 229/248 passed, 17 skipped | | `run_semantic_tests.py tests/semantic` | 465 files, 6108 tests, 0 files failed in 101 s with 16 jobs | 465 files, 6108 tests, 0 files failed | No new GPU fixture; no change in the GPU results against `main`. The only failures in both runs are the known `cs_imgload_tfe` / `cs_imgload_d16_tfe` pair (#31), as on `main`. No regressions. AI-assisted: yes (Claude Code ran the build and tests on my machine; numbers are the runners' own output).
This pull request has changes conflicting with the target branch.
  • docs/design.md
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/40/head:github-bot/gh-40'
git switch 'github-bot/gh-40'

Merge

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