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

Open
opened 2026-11-26 20:16:46 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/40
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/5237


📝 Commits (3)

  • 5c85e23 rdna2spirv: the PS FRONT_FACE VGPR holds 0xffffffff / 0, the form the game's shaders test (SHADER-892)
  • eea1754 docs/design.md: the FRONT_FACE count rules out ±1.0; all-bits over 1/0 is the hardware's other form
  • ecaaf14 Merge main into fix/front-face-mask

📊 Changes

3 files changed (+56 additions, -5 deletions)

View changed files

📝 docs/design.md (+1 -1)
➕ tests/test_ps_front_face.py (+47 -0)
📝 tools/rdna2spirv.py (+8 -4)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/40 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/5237` --- ### 📝 Commits (3) - [`5c85e23`](https://github.com/ubiquitarianism/leonida/commit/5c85e233a76771c56554db6aff0e24c3c1b99cef) rdna2spirv: the PS FRONT_FACE VGPR holds 0xffffffff / 0, the form the game's shaders test (SHADER-892) - [`eea1754`](https://github.com/ubiquitarianism/leonida/commit/eea1754ea4a2b319449e04257a70e10aabacfd28) docs/design.md: the FRONT_FACE count rules out ±1.0; all-bits over 1/0 is the hardware's other form - [`ecaaf14`](https://github.com/ubiquitarianism/leonida/commit/ecaaf14b9de986464f2e2aa9b85adf2680e0207b) Merge main into fix/front-face-mask ### 📊 Changes **3 files changed** (+56 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) ➕ `tests/test_ps_front_face.py` (+47 -0) 📝 `tools/rdna2spirv.py` (+8 -4) </details> ### 📄 Description > 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#93
No description provided.