fix(shader): honour SPI_BARYC_CNTL.FRONT_FACE_ALL_BITS for the front-face input #5314

Merged
XairRrR merged 2 commits from upstream-pr/5314 into main 2026-10-14 20:43:52 +00:00
XairRrR commented 2026-10-13 17:01:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-13T17:01:52Z.


What

The pixel shader's front-face VGPR was always +1.0 / -1.0. That is its form only while SPI_BARYC_CNTL.FRONT_FACE_ALL_BITS (bit 24) is clear. With the bit set, a back face reads 0 and a front face non-zero:

  • Mesa 22.0 RADV sets the bit (radv_pipeline.c), and ACO tests the input with v_cmp_lg_u32 0, front_face (aco_instruction_selection.cpp).
  • Current RADV clears the bit and reads the input as a float (fgt 0, and fsign for ±1.0, in ac_nir_lower_intrinsics_to_args.c). That is the form the driver produced until now.

Uncharted: Legacy of Thieves Collection (PPSA05684) sets the bit. Its two-sided cloth shaders enable FRONT_FACE (SPI_PS_INPUT_ENA = 0x1b02, so the input is v5) and test it with v_cmp_lt_u32 0, v5. -1.0 (0xbf800000) is non-zero, so every back face was taken as a front face. The insides of the menu skeleton's rags kept their front normals and were lit white by the spot light behind the cage. With this change the rags render dark, as on the PC version.

Changes:

  • ShaderPixelStageInfo::frontFaceAllBits, decoded from SPI_BARYC_CNTL only when FRONT_FACE is an active input, so contexts without the input don't need the register.
  • The flag is in the request serialization (version 27, after main's version 26 linked call fallbacks, with a version 26 replay case; RequestSerializerTests upgrades older fixtures to version 27), the shader cache key, the draw lookup key and the draw register key comparison. DrawKeyRegisters covers 0x1b6..0x1b8.
  • With the bit set, the translator turns the FrontFacing builtin into 0xffffffff / 0.
  • The exact front value (0xffffffff) is not measured; only back = 0 and front ≠ 0 are sourced. It is listed in docs/dev/debt/shader.md.

Tested

  • Arch Linux, NVIDIA GeForce RTX 4070 Ti SUPER, driver 615.78.08, Release.
  • New agc_driver_front_face_all_bits: a front-facing and a back-facing triangle export the raw front-face VGPR into an R32_UINT target. It expects 0x3f800000 / 0xbf800000 without the bit and 0xffffffff / 0 with it. With the translator change reverted, it fails with with FRONT_FACE_ALL_BITS: the front-facing triangle read FRONT_FACE as 0x3f800000, expected 0xffffffff.
  • agc_driver_graphics decodes the bit (set, clear, and set without the front-face input). agc_shader_memory round-trips the flag and replays a version 26 request.
  • Full ctest: 1179 of 1179 on main 32e810db4, before adriadam10's rebase onto version 27 (he re-ran the affected tests on the rebase). tools/check_conventions.py --base origin/main passes.
  • PPSA05684 menu on a local stack (it does not run on main yet, it needs #757/#758): the white rags are gone and the skeleton matches the PC reference.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA05684 #4001 (white cloth in the main menu)
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti SUPER, driver 615.78.08, Arch Linux (kernel 7.2.9)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4846680562 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5314). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-13T17:01:52Z. --- ### What The pixel shader's front-face VGPR was always `+1.0` / `-1.0`. That is its form only while `SPI_BARYC_CNTL.FRONT_FACE_ALL_BITS` (bit 24) is clear. With the bit set, a back face reads `0` and a front face non-zero: - Mesa 22.0 RADV sets the bit ([radv_pipeline.c](https://gitlab.freedesktop.org/mesa/mesa/-/blob/mesa-22.0.0/src/amd/vulkan/radv_pipeline.c#L5953)), and ACO tests the input with `v_cmp_lg_u32 0, front_face` ([aco_instruction_selection.cpp](https://gitlab.freedesktop.org/mesa/mesa/-/blob/mesa-22.0.0/src/amd/compiler/aco_instruction_selection.cpp#L8123-L8128)). - Current RADV clears the bit and reads the input as a float (`fgt 0`, and `fsign` for `±1.0`, in `ac_nir_lower_intrinsics_to_args.c`). That is the form the driver produced until now. Uncharted: Legacy of Thieves Collection (PPSA05684) sets the bit. Its two-sided cloth shaders enable FRONT_FACE (`SPI_PS_INPUT_ENA = 0x1b02`, so the input is `v5`) and test it with `v_cmp_lt_u32 0, v5`. `-1.0` (`0xbf800000`) is non-zero, so every back face was taken as a front face. The insides of the menu skeleton's rags kept their front normals and were lit white by the spot light behind the cage. With this change the rags render dark, as on the PC version. Changes: - `ShaderPixelStageInfo::frontFaceAllBits`, decoded from `SPI_BARYC_CNTL` only when FRONT_FACE is an active input, so contexts without the input don't need the register. - The flag is in the request serialization (version 27, after main's version 26 linked call fallbacks, with a version 26 replay case; `RequestSerializerTests` upgrades older fixtures to version 27), the shader cache key, the draw lookup key and the draw register key comparison. `DrawKeyRegisters` covers `0x1b6..0x1b8`. - With the bit set, the translator turns the FrontFacing builtin into `0xffffffff` / `0`. - The exact front value (`0xffffffff`) is not measured; only back = 0 and front ≠ 0 are sourced. It is listed in `docs/dev/debt/shader.md`. ### Tested - Arch Linux, NVIDIA GeForce RTX 4070 Ti SUPER, driver 615.78.08, Release. - New `agc_driver_front_face_all_bits`: a front-facing and a back-facing triangle export the raw front-face VGPR into an R32_UINT target. It expects `0x3f800000` / `0xbf800000` without the bit and `0xffffffff` / `0` with it. With the translator change reverted, it fails with `with FRONT_FACE_ALL_BITS: the front-facing triangle read FRONT_FACE as 0x3f800000, expected 0xffffffff`. - `agc_driver_graphics` decodes the bit (set, clear, and set without the front-face input). `agc_shader_memory` round-trips the flag and replays a version 26 request. - Full ctest: 1179 of 1179 on `main` 32e810db4, before adriadam10's rebase onto version 27 (he re-ran the affected tests on the rebase). `tools/check_conventions.py --base origin/main` passes. - PPSA05684 menu on a local stack (it does not run on `main` yet, it needs #757/#758): the white rags are gone and the skeleton matches the PC reference. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA05684 #4001 (white cloth in the main menu) - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti SUPER, driver 615.78.08, Arch Linux (kernel 7.2.9) - [x] AI-assisted: yes
adriadam10 commented 2026-10-14 19:10:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T19:10:53Z.


Checked on a build merged onto current main: agc_driver_graphics, agc_shader_memory (incl. the version 25 replay), agc_driver_front_face_all_bits and the prepared-graphics tests pass; the flag is in the serialization, shader cache key, draw lookup key and draw register comparison. The only red test in the scoped run, agc_driver_tessellation, segfaults inside libvulkan_radeon.so on a tree without this PR too. Minor: the body says "replays a version 23 request", the test replays version 25. The front value 0xffffffff is unmeasured and listed in the debt file; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6176228476 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5314#issuecomment-6176228476). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T19:10:53Z. --- Checked on a build merged onto current main: `agc_driver_graphics`, `agc_shader_memory` (incl. the version 25 replay), `agc_driver_front_face_all_bits` and the prepared-graphics tests pass; the flag is in the serialization, shader cache key, draw lookup key and draw register comparison. The only red test in the scoped run, `agc_driver_tessellation`, segfaults inside `libvulkan_radeon.so` on a tree without this PR too. Minor: the body says "replays a version 23 request", the test replays version 25. The front value `0xffffffff` is unmeasured and listed in the debt file; merging.
adriadam10 commented 2026-10-14 19:40:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T19:40:00Z.


Rebased onto current main, which took serialization version 26 for the linked call fallbacks in the meantime. The front-face all-bits flag is now serialized in version 27 (RequestSerializer.cpp); RequestSerializerTests.cpp and ShaderMemory.cpp follow (upgrade fixtures, the replay case is now a version 26 request, the "unsupported version" fixture is 28). Re-ran agc_shader_memory, agc_driver_graphics, agc_driver_front_face_all_bits, the serializer and prepared-graphics tests on the rebase: green. agc_driver_tessellation still segfaults in libvulkan_radeon.so, as on main. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6176784843 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5314#issuecomment-6176784843). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T19:40:00Z. --- Rebased onto current `main`, which took serialization version 26 for the linked call fallbacks in the meantime. The front-face all-bits flag is now serialized in version 27 (`RequestSerializer.cpp`); `RequestSerializerTests.cpp` and `ShaderMemory.cpp` follow (upgrade fixtures, the replay case is now a version 26 request, the "unsupported version" fixture is 28). Re-ran `agc_shader_memory`, `agc_driver_graphics`, `agc_driver_front_face_all_bits`, the serializer and prepared-graphics tests on the rebase: green. `agc_driver_tessellation` still segfaults in `libvulkan_radeon.so`, as on `main`. Merging once the full Build is green.
github-actions[bot] commented 2026-10-14 19:41:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T19:41:28Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5200 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L2905, L3020-3021, L3023, L3139-3142
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp L341, L393, L765, L798
core/shader/recompiler/tests/RequestSerializerTests.cpp L205-206, L243-244, L267-268, L390-391, L405, L407
#6015 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L2905, L3020-3021, L3023, L3141
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp L341, L393, L765, L798
core/shader/recompiler/tests/RequestSerializerTests.cpp L205-206, L243-244, L267-268, L390-391, L405, L407
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6176812951 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5314#issuecomment-6176812951). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T19:41:28Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5200 | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` [L2905](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L2905), [L3020-3021](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L3020-L3021), [L3023](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L3023), [L3139-3142](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L3139-L3142)<br>`core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp` [L341](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp#L341), [L393](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp#L393), [L765](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp#L765), [L798](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp#L798)<br>`core/shader/recompiler/tests/RequestSerializerTests.cpp` [L205-206](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/tests/RequestSerializerTests.cpp#L205-L206), [L243-244](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/tests/RequestSerializerTests.cpp#L243-L244), [L267-268](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/tests/RequestSerializerTests.cpp#L267-L268), [L390-391](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/tests/RequestSerializerTests.cpp#L390-L391), [L405](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/tests/RequestSerializerTests.cpp#L405), [L407](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/tests/RequestSerializerTests.cpp#L407) | | | | #6015 | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` [L2905](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L2905), [L3020-3021](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L3020-L3021), [L3023](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L3023), [L3141](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L3141)<br>`core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp` [L341](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp#L341), [L393](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp#L393), [L765](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp#L765), [L798](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp#L798)<br>`core/shader/recompiler/tests/RequestSerializerTests.cpp` [L205-206](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/tests/RequestSerializerTests.cpp#L205-L206), [L243-244](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/tests/RequestSerializerTests.cpp#L243-L244), [L267-268](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/tests/RequestSerializerTests.cpp#L267-L268), [L390-391](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/tests/RequestSerializerTests.cpp#L390-L391), [L405](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/tests/RequestSerializerTests.cpp#L405), [L407](https://github.com/boykopovar/AnyPS5/blob/7003eda5d6ef1ec93f032535f9af8bb697092201/core/shader/recompiler/tests/RequestSerializerTests.cpp#L407) | | |
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
boykopovar/AnyPS5!5314
No description provided.