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

Closed
Andretuta wants to merge 3 commits from upstream-pr/40 into main
Andretuta commented 2026-11-24 02:05:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:05:36Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5464695707 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/40). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:05:36Z. --- > 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.
ImLele69 commented 2026-11-24 11:37:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ImLele69 on 2026-11-24T11:37:16Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7130332580 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/40#issuecomment-7130332580). Originally posted by [ImLele69](https://github.com/ImLele69) on 2026-11-24T11:37:16Z. --- 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).
MoonEyes commented 2026-11-27 19:42:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T19:42:52Z.


Thanks a lot for carrying this over, @Andretuta. The same change is open in #1415, rebased on current main with the commit by rafaelpssz (old PR 5237) kept: tools/rdna2spirv.py and tests/test_ps_front_face.py change in the same way, and the docs/design.md row is the same except for a leftover fragment at the end of the sentence, which #1415 removes.

I am closing this draft to keep the queue clear. Please continue the discussion in #1415, or reopen this one if something is missing there.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7226798706 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/40#issuecomment-7226798706). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T19:42:52Z. --- Thanks a lot for carrying this over, @Andretuta. The same change is open in #1415, rebased on current `main` with the commit by `rafaelpssz` (old PR 5237) kept: `tools/rdna2spirv.py` and `tests/test_ps_front_face.py` change in the same way, and the `docs/design.md` row is the same except for a leftover fragment at the end of the sentence, which #1415 removes. I am closing this draft to keep the queue clear. Please continue the discussion in #1415, or reopen this one if something is missing there. AI-assisted (Claude Code, Claude Opus 5.5)

Pull request closed

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
ProjectLeonida/mandy!40
No description provided.