fix(agc): read blend constant registers only for active channels #21241

Merged
birdmarty merged 2 commits from upstream-pr/21241 into main 2026-11-19 09:12:35 +00:00
birdmarty commented 2026-11-16 01:21:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by birdmarty on 2026-11-16T01:21:26Z.


What

DecodeState previously called readFloat(cx, 0x105 + i) on all four CB_BLEND0..3 registers (DWORD 261..264) whenever color blending was enabled, causing AGC graphics: non-finite register at DWORD 261 if a draw left stale NaN/Inf bits in blend constant registers it did not use (for example when blending did not use constant factors, used MIN/MAX, or masked off those channels).

  • Extracted translateReversedBlendWith so reversed-order target decoding reads 0x105 + component only for constant-factor channels that are actually needed, while keeping TranslateReversedBlend unchanged.
  • Updated standard blend decoding in DecodeState (and deduplicated recordBlendConstant) so 0x105..0x108 are only read for unmasked written channels whose active blend factor and blend operation actually consume those constants, leaving unused channels zero-initialized.
  • Added unit tests in Color565TargetTests and ReversedComponentOrderBlendTests covering NaN/Inf in unused CB_BLEND registers as well as rejection when an active constant channel is non-finite.

Tested

  • Windows 11 (10.0.26300), AMD Radeon RX 6800 (AMD proprietary driver 26.10.1 / 32.0.21045.16010):
    • Far Cry 6 (PPSA01870, 01.000.013): Before the change, crashed during presentation with [gpu] driver failure: AGC graphics: non-finite register at DWORD 261 / FATAL: abort() (SIGABRT). With the State.cpp fix in libSceAgcDriver.prx, a 178.879 s run presented 7367 frames (43.167 fps avg, firstPresent at 7.830 s), compiled 3489 shaders (0 failed, 984 cache hits), and exited cleanly on window close.
    • Vulkan validation ctest comparison (origin/main d31916ed37 vs. branch) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer:
      • ctest --test-dir build -R "^(agc_driver_graphics|agc_driver_reversed_order_blend)$" -V
      • origin/main: 2/2 passed (agc_driver_reversed_order_blend 1.80 sec, agc_driver_graphics 19.45 sec), Insert instance layer "VK_LAYER_KHRONOS_validation" confirmed, 0 was not found, 0 VUID- errors.
      • Branch: 2/2 passed (agc_driver_reversed_order_blend 1.20 sec, agc_driver_graphics 20.18 sec), Insert instance layer "VK_LAYER_KHRONOS_validation" confirmed, 0 was not found, 0 VUID- errors.
    • python tools/check_conventions.py --base origin/main: passed.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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
  • Fixes: none
  • Unblocks: PPSA01870 #21239
  • GPUs tested: AMD, AMD Radeon RX 6800, driver 32.0.21045.16010 (Adrenalin 26.10.1), Windows 11 (10.0.26300)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5329381678 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21241). Originally posted by [birdmarty](https://github.com/birdmarty) on 2026-11-16T01:21:26Z. --- ### What `DecodeState` previously called `readFloat(cx, 0x105 + i)` on all four `CB_BLEND0..3` registers (`DWORD 261..264`) whenever color blending was enabled, causing `AGC graphics: non-finite register at DWORD 261` if a draw left stale `NaN`/`Inf` bits in blend constant registers it did not use (for example when blending did not use constant factors, used `MIN`/`MAX`, or masked off those channels). - Extracted `translateReversedBlendWith` so reversed-order target decoding reads `0x105 + component` only for constant-factor channels that are actually needed, while keeping `TranslateReversedBlend` unchanged. - Updated standard blend decoding in `DecodeState` (and deduplicated `recordBlendConstant`) so `0x105..0x108` are only read for unmasked written channels whose active blend factor and blend operation actually consume those constants, leaving unused channels zero-initialized. - Added unit tests in `Color565TargetTests` and `ReversedComponentOrderBlendTests` covering `NaN`/`Inf` in unused `CB_BLEND` registers as well as rejection when an active constant channel is non-finite. ### Tested - **Windows 11 (`10.0.26300`), AMD Radeon RX 6800 (AMD proprietary driver `26.10.1` / `32.0.21045.16010`)**: - **Far Cry 6 (`PPSA01870`, `01.000.013`)**: Before the change, crashed during presentation with `[gpu] driver failure: AGC graphics: non-finite register at DWORD 261` / `FATAL: abort() (SIGABRT)`. With the `State.cpp` fix in `libSceAgcDriver.prx`, a `178.879 s` run presented `7367` frames (`43.167 fps` avg, `firstPresent` at `7.830 s`), compiled `3489` shaders (`0` failed, `984` cache hits), and exited cleanly on window close. - **Vulkan validation `ctest` comparison (`origin/main` `d31916ed37` vs. branch)** with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `VK_LOADER_DEBUG=layer`: - `ctest --test-dir build -R "^(agc_driver_graphics|agc_driver_reversed_order_blend)$" -V` - `origin/main`: `2/2` passed (`agc_driver_reversed_order_blend` `1.80 sec`, `agc_driver_graphics` `19.45 sec`), `Insert instance layer "VK_LAYER_KHRONOS_validation"` confirmed, `0` `was not found`, `0` `VUID-` errors. - Branch: `2/2` passed (`agc_driver_reversed_order_blend` `1.20 sec`, `agc_driver_graphics` `20.18 sec`), `Insert instance layer "VK_LAYER_KHRONOS_validation"` confirmed, `0` `was not found`, `0` `VUID-` errors. - `python tools/check_conventions.py --base origin/main`: passed. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) and the licence notice of code adapted from upstream (see AGENTS.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] Fixes: none - [x] Unblocks: PPSA01870 #21239 - [x] GPUs tested: AMD, AMD Radeon RX 6800, driver 32.0.21045.16010 (Adrenalin 26.10.1), Windows 11 (10.0.26300) - [x] AI-assisted: yes
MarcZX10 commented 2026-11-16 02:28:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T02:28:30Z.

Review: APPROVED


Reviewed — looks good

The changed blend decoding and its regression cases are supported by the inspected code; the review is complete, but the reported test runs were not independently rerun here.

What I ran

Read the prepared diff at head 9d5df0a28fe29ecd2dab27aa6fbf95c6771cb6d3 and inspected the changed decode logic and regression cases through repo_read.py. No tests or build commands were run. The author-reported test results are not independent runs.

Results

Check Result Note
Source review passed Decode paths and tests inspected
Automated checks not run Results in description only

Findings

Blocking

None.

Non-blocking

None.

Not verified

The full Graphics.cpp file was excluded from the review folder, but the changed test ranges were read through repo_read.py. Other parts of that test file were not read. Tests, builds, Vulkan validation, and the reported Far Cry 6 run were not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5914372615 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21241#pullrequestreview-5914372615). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T02:28:30Z. **Review:** APPROVED --- # Reviewed — looks good The changed blend decoding and its regression cases are supported by the inspected code; the review is complete, but the reported test runs were not independently rerun here. ## What I ran Read the prepared diff at head `9d5df0a28fe29ecd2dab27aa6fbf95c6771cb6d3` and inspected the changed decode logic and regression cases through `repo_read.py`. No tests or build commands were run. The author-reported test results are not independent runs. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Decode paths and tests inspected | | Automated checks | not run | Results in description only | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The full `Graphics.cpp` file was excluded from the review folder, but the changed test ranges were read through `repo_read.py`. Other parts of that test file were not read. Tests, builds, Vulkan validation, and the reported Far Cry 6 run were not independently verified. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-16 02:42:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T02:42:47Z.

Review: COMMENTED


Reviewed — no blocking findings

The changed blend decoding and regression tests appear sound at head 915b83cbe07c62a915d2e8b0fbf7f04e6eeeff3b; no checks were run during this review, and the reported hardware and CI runs are author-supplied.

What I ran

  • Read the prepared change description, commit list, manifest, diff, changed source file, and targeted test ranges at the pinned head.
  • No commands or tests were run.

Results

Check Result Note
Source and diff review passed Blend constant read paths inspected
Tests not run New tests reviewed, not executed
Author-reported checks not run Windows and CI details were not independently confirmed

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • The full changed test file was excluded from the review bundle because it was too large; targeted test sections were read through the pinned repository reader. Other unshown parts of that file were not reviewed.
  • The hardware run, Vulkan validation ctest comparison, and conventions check in the description are author-reported and were not run here.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5914451079 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21241#pullrequestreview-5914451079). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T02:42:47Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The changed blend decoding and regression tests appear sound at head `915b83cbe07c62a915d2e8b0fbf7f04e6eeeff3b`; no checks were run during this review, and the reported hardware and CI runs are author-supplied. ## What I ran - Read the prepared change description, commit list, manifest, diff, changed source file, and targeted test ranges at the pinned head. - No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Source and diff review | passed | Blend constant read paths inspected | | Tests | not run | New tests reviewed, not executed | | Author-reported checks | not run | Windows and CI details were not independently confirmed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - The full changed test file was excluded from the review bundle because it was too large; targeted test sections were read through the pinned repository reader. Other unshown parts of that file were not reviewed. - The hardware run, Vulkan validation `ctest` comparison, and conventions check in the description are author-reported and were not run here. ## To get this to a good state Nothing is required.
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!21241
No description provided.