feat(agc): merge a draw into more than one unclamped normalized color target #12916

Merged
Tehshortbus merged 1 commit from upstream-pr/12916 into main 2026-10-30 03:49:47 +00:00
Tehshortbus commented 2026-10-29 14:16:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Tehshortbus on 2026-10-29T14:16:07Z.


What

A draw that blends into more than one color target with BLEND_CLAMP clear stopped with a draw merges into one color target at most, so blending unclamped normalized color cannot join another merged color target. PPSA26344 (02.002.000) stops on such a draw while it streams its first world cell (#12796). The title's log names MRT1 (CB_COLOR_INFO 0x0000000c, CB_BLEND1_CONTROL 0x40010504). In #675, MRT0 was reported with the same values before #11684. This follows the shape @oneandonlydean suggested on the issue: a list of merge entries, one interlock region, and a two-target case in the unclamped-blend execution test.

  • Request. ShaderPixelStageInfo::targetMerge becomes targetMerges, one entry per merged target. ExportTargetMerges returns an entry for every target with a partial write mask. The cache key, the draw lookup hash, the draw register key and the recompiler's variant hash cover every entry.
  • Serialization. The first entry keeps the version 46 layout. Bits 17..19 of its mask word count the entries that follow it, the way bit 16 already flags a blend, so the version stays 49. Requests with no merge or one merge serialize to the same bytes as before. A request with more than eight entries is refused when written, and so is an entry with no mask, other than the lone default, when read.
  • SPIR-V. Each entry gets its own storage image, its own merged value and pending flag, and its own blend state. Every MRT export merges into the entry for its slot. FlushColorTargetMerge stores each pending entry inside the draw's one pixel interlock region.
  • Driver.
    • Several unclamped blends can merge in one draw. A partial write of a packed (4_4_4_4) target still merges alone, and an unclamped blend still cannot join it; both refusals say so. Merged targets whose memory overlaps are refused.
    • A merged target's blend attachment is reset to the empty state rather than only having its enable and write mask cleared. Without independentBlend, two merged targets with different blend equations otherwise gave different pAttachments (VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605).
  • Debt. The unclamped normalized targets entry now lists a packed target's partial write in the same draw as refused, in place of the second merged target. A new 4_4_4_4 entry records that a partial write merges alone, and that merged targets sharing memory throw.

24 files, +371/−212. The tests are +222/−84: the existing tests that read targetMerge move to the list, and the rest are the new cases below.

Tested

CachyOS Linux (kernel 7.3.0-4-cachyos), GCC 16.2.1, Release, NVIDIA GeForce RTX 4070 SUPER (615.78.08).

Head c037722384 on main 1b75a2de11. The tests below ran on the same change on main b0465557fd (47bdfe07a2). None of the 26 commits between the two mains touch this PR's files.

  • New cases:

    • agc_driver_graphics:

      • Two slots with CB_COLOR_INFO 0x0000000c and CB_BLEND0_CONTROL/CB_BLEND1_CONTROL 0x40010504 at different addresses decode into two merge entries for MRT0 and MRT1. Each has its own descriptor and SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ADD for color and alpha.
      • With CB_BLEND1_CONTROL set to ONE, ONE, each entry keeps its own factors.
      • Two merged targets at the same address are refused.
      • A 4_4_4_4 partial write in slot 1 after the blend, and in slot 0 before it, are both refused with the new messages.
    • agc_driver_unclamped_normalized_blend: one draw exports MRT0 and MRT1 and blends both, checked per pixel against the CPU reference, on the stored channels:

      • two 8_8 UNORM targets with SRC_ALPHA, ONE_MINUS_SRC_ALPHA and out-of-range sources;
      • an 8_8_8_8 UNORM MRT0 with ONE, ONE and an 8_8 UNORM MRT1 with SUBTRACT, so the entries carry different blend equations.

      Every draw in the test, including the 20 existing single-target ones, also checks that its pixel shader has one interlock begin and stores every merged target inside it. The test builds the draw state itself, so it reaches the request, the SPIR-V and the pipeline but not register decode; decode is covered by agc_driver_graphics.

    • agc_shader_memory:

      • A request with two merge entries round-trips, and its second entry follows the first with the count in the first mask word.
      • A second entry with no mask is refused when read, and nine entries are refused when written.
      • The static shader identity changes with a second entry, and with its slot or blend, but not with its descriptor.
  • Focused run. ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build-tests -V -R '^(request_serializer|agc_shader_memory|agc_driver_graphics|agc_driver_packed_unorm4444_color_target|agc_driver_packed_unorm4444_multisample_partial_write|agc_driver_packed_unorm4444_partial_write|agc_driver_unclamped_normalized_blend)$'

    main b0465557fd this change
    tests 7/7 pass 7/7 pass
    VUID- lines 0 0
    was not found but was requested by env var VK_INSTANCE_LAYERS 0 0
  • Full suite. 2905 of 2906 pass under the same environment, with no VUID- line. guest_freebsd_clocks fails because the host zone is not UTC (#12736) and passes with TZ=UTC.

  • Negative controls. Each control breaks one piece of the change; each is caught:

    Change made Result
    main's refusal of any second merged target agc_driver_graphics fails with the title's message
    only the first entry is stored agc_driver_unclamped_normalized_blend fails: not every merged target is stored inside the interlock region
    every entry blends with the first entry's blend state agc_driver_unclamped_normalized_blend fails on MRT1's pixels
    merged blend attachments keep their factors agc_driver_unclamped_normalized_blend passes, but the validation layer reports VUID-…-00605 twice
    the serializer does not count further entries agc_shader_memory fails
  • PPSA26344 (02.002.000). One run each from launch, same files and settings, with anyps5-entitlements.ini listing the add-on label the title needs:

    Build Result Presents
    main 5454cd2e45 aborts at 303 s with the refusal above (exit 134) 397
    this change on 5454cd2e45 (3cbd74244b) passes that frame and keeps loading, showing the title's loading spinner; closed by hand at 1966 s with no driver failure 550
    this change, head c037722384 passes that frame, plays the title's audio and controller rumble, then slows to under 0.1 fps with the texture caches unable to free memory (5118 MiB of 9038 MiB in sampled textures); closed by hand at 793 s with no driver failure 560

    These runs show the draw no longer stops the title. They don't show that the merged targets look right, since main never got past this point to compare against; the execution test checks that.

  • python3 tools/check_conventions.py --base origin/main and git diff --check pass.

Not checked:

  • Windows, AMD and Intel GPUs.
  • Registration modules with two merges.
  • The command-buffer draw path with two merges (DrawDecode, DrawLookup, DrawRegisterKey), other than in the PPSA26344 run.
  • Two merged targets of a multisampled draw: unclamped blends need single-sample targets, and packed partial writes merge alone.
  • Gameplay in the title: the runs stayed in its loading stretch.

A merged target beside a target that blends normally still gives that target's attachment state next to an empty one. Without independentBlend this is the same pAttachments difference as on main before this change; the focused and full runs report no VUID- line for it.

Overlap. tools/pr_overlap.py (main 609422fefe) reports no overlap for the pull requests it could compare. For the 77 it could not, I merged each with this branch and with main and compared the conflicts in shared files:

  • Same merge path (3): #9020, #9335 and #9748 extend the single TargetMerge. This branch adds conflicts in CacheKey.hpp, DrawLookup.cpp, Recompiler.cpp, ShaderStageInputInfo.hpp and ShaderInputInfoBuilder.cpp, and its lines fall inside their existing conflicts in RequestSerializer.cpp, SpirvModuleEmitter.cpp, State.cpp and ShaderMemory.cpp.
  • Adjacent lines (3):
    • #11557: the packed refusal in State.cpp and the multisampled 4_4_4_4 tests.
    • #11551: DrawRegisterKey.cpp and ShaderInfoCollector.cpp.
    • #6235: its existing conflicts in State.cpp, CacheKey.hpp, Recompiler.hpp and SpirvModuleEmitter.cpp.
  • This branch's line inside a conflict the PR already has with main (7): #6194, #6223 and #6548 (libSceAgcDriver.md); #8004, #9356 and #9387 (RequestSerializerTests.cpp); #12662 (ShaderMemory.cpp).
  • The other 64: the same conflicts with this branch as with main.

All 13 are older, so this lands after them, recorded in Depends on. I'll rebase onto whichever merges first.

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: #6194, #6223, #6235, #6548, #8004, #9020, #9335, #9356, #9387, #9748, #11551, #11557, #12662
  • Fixes: #12796
  • Unblocks: PPSA26344 #675
  • GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 615.78.08, CachyOS Linux (kernel 7.3.0-4-cachyos)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5069649146 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12916). Originally posted by [Tehshortbus](https://github.com/Tehshortbus) on 2026-10-29T14:16:07Z. --- ### What A draw that blends into more than one color target with BLEND_CLAMP clear stopped with `a draw merges into one color target at most, so blending unclamped normalized color cannot join another merged color target`. PPSA26344 (02.002.000) stops on such a draw while it streams its first world cell (#12796). The title's log names MRT1 (`CB_COLOR_INFO 0x0000000c`, `CB_BLEND1_CONTROL 0x40010504`). In #675, MRT0 was reported with the same values before #11684. This follows the shape @oneandonlydean suggested on the issue: a list of merge entries, one interlock region, and a two-target case in the unclamped-blend execution test. - **Request.** `ShaderPixelStageInfo::targetMerge` becomes `targetMerges`, one entry per merged target. `ExportTargetMerges` returns an entry for every target with a partial write mask. The cache key, the draw lookup hash, the draw register key and the recompiler's variant hash cover every entry. - **Serialization.** The first entry keeps the version 46 layout. Bits 17..19 of its mask word count the entries that follow it, the way bit 16 already flags a blend, so the version stays 49. Requests with no merge or one merge serialize to the same bytes as before. A request with more than eight entries is refused when written, and so is an entry with no mask, other than the lone default, when read. - **SPIR-V.** Each entry gets its own storage image, its own merged value and pending flag, and its own blend state. Every MRT export merges into the entry for its slot. `FlushColorTargetMerge` stores each pending entry inside the draw's one pixel interlock region. - **Driver.** - Several unclamped blends can merge in one draw. A partial write of a packed (4_4_4_4) target still merges alone, and an unclamped blend still cannot join it; both refusals say so. Merged targets whose memory overlaps are refused. - A merged target's blend attachment is reset to the empty state rather than only having its enable and write mask cleared. Without `independentBlend`, two merged targets with different blend equations otherwise gave different `pAttachments` (`VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605`). - **Debt.** The unclamped normalized targets entry now lists a packed target's partial write in the same draw as refused, in place of the second merged target. A new 4_4_4_4 entry records that a partial write merges alone, and that merged targets sharing memory throw. 24 files, +371/−212. The tests are +222/−84: the existing tests that read `targetMerge` move to the list, and the rest are the new cases below. ### Tested CachyOS Linux (kernel 7.3.0-4-cachyos), GCC 16.2.1, Release, NVIDIA GeForce RTX 4070 SUPER (615.78.08). Head `c037722384` on `main` `1b75a2de11`. The tests below ran on the same change on `main` `b0465557fd` (`47bdfe07a2`). None of the 26 commits between the two `main`s touch this PR's files. - **New cases:** - `agc_driver_graphics`: - Two slots with `CB_COLOR_INFO 0x0000000c` and `CB_BLEND0_CONTROL`/`CB_BLEND1_CONTROL 0x40010504` at different addresses decode into two merge entries for MRT0 and MRT1. Each has its own descriptor and SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ADD for color and alpha. - With `CB_BLEND1_CONTROL` set to ONE, ONE, each entry keeps its own factors. - Two merged targets at the same address are refused. - A 4_4_4_4 partial write in slot 1 after the blend, and in slot 0 before it, are both refused with the new messages. - `agc_driver_unclamped_normalized_blend`: one draw exports MRT0 and MRT1 and blends both, checked per pixel against the CPU reference, on the stored channels: - two 8_8 UNORM targets with SRC_ALPHA, ONE_MINUS_SRC_ALPHA and out-of-range sources; - an 8_8_8_8 UNORM MRT0 with ONE, ONE and an 8_8 UNORM MRT1 with SUBTRACT, so the entries carry different blend equations. Every draw in the test, including the 20 existing single-target ones, also checks that its pixel shader has one interlock begin and stores every merged target inside it. The test builds the draw state itself, so it reaches the request, the SPIR-V and the pipeline but not register decode; decode is covered by `agc_driver_graphics`. - `agc_shader_memory`: - A request with two merge entries round-trips, and its second entry follows the first with the count in the first mask word. - A second entry with no mask is refused when read, and nine entries are refused when written. - The static shader identity changes with a second entry, and with its slot or blend, but not with its descriptor. - **Focused run.** `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build-tests -V -R '^(request_serializer|agc_shader_memory|agc_driver_graphics|agc_driver_packed_unorm4444_color_target|agc_driver_packed_unorm4444_multisample_partial_write|agc_driver_packed_unorm4444_partial_write|agc_driver_unclamped_normalized_blend)$'` | | `main` `b0465557fd` | this change | |---|---|---| | tests | 7/7 pass | 7/7 pass | | `VUID-` lines | 0 | 0 | | `was not found but was requested by env var VK_INSTANCE_LAYERS` | 0 | 0 | - **Full suite.** 2905 of 2906 pass under the same environment, with no `VUID-` line. `guest_freebsd_clocks` fails because the host zone is not UTC (#12736) and passes with `TZ=UTC`. - **Negative controls.** Each control breaks one piece of the change; each is caught: | Change made | Result | |---|---| | `main`'s refusal of any second merged target | `agc_driver_graphics` fails with the title's message | | only the first entry is stored | `agc_driver_unclamped_normalized_blend` fails: not every merged target is stored inside the interlock region | | every entry blends with the first entry's blend state | `agc_driver_unclamped_normalized_blend` fails on MRT1's pixels | | merged blend attachments keep their factors | `agc_driver_unclamped_normalized_blend` passes, but the validation layer reports `VUID-…-00605` twice | | the serializer does not count further entries | `agc_shader_memory` fails | - **PPSA26344 (02.002.000).** One run each from launch, same files and settings, with `anyps5-entitlements.ini` listing the add-on label the title needs: | Build | Result | Presents | |---|---|---| | `main` `5454cd2e45` | aborts at 303 s with the refusal above (exit 134) | 397 | | this change on `5454cd2e45` (`3cbd74244b`) | passes that frame and keeps loading, showing the title's loading spinner; closed by hand at 1966 s with no driver failure | 550 | | this change, head `c037722384` | passes that frame, plays the title's audio and controller rumble, then slows to under 0.1 fps with the texture caches unable to free memory (5118 MiB of 9038 MiB in sampled textures); closed by hand at 793 s with no driver failure | 560 | These runs show the draw no longer stops the title. They don't show that the merged targets look right, since `main` never got past this point to compare against; the execution test checks that. - `python3 tools/check_conventions.py --base origin/main` and `git diff --check` pass. **Not checked:** - Windows, AMD and Intel GPUs. - Registration modules with two merges. - The command-buffer draw path with two merges (`DrawDecode`, `DrawLookup`, `DrawRegisterKey`), other than in the PPSA26344 run. - Two merged targets of a multisampled draw: unclamped blends need single-sample targets, and packed partial writes merge alone. - Gameplay in the title: the runs stayed in its loading stretch. A merged target beside a target that blends normally still gives that target's attachment state next to an empty one. Without `independentBlend` this is the same `pAttachments` difference as on `main` before this change; the focused and full runs report no `VUID-` line for it. **Overlap.** `tools/pr_overlap.py` (`main` `609422fefe`) reports no overlap for the pull requests it could compare. For the 77 it could not, I merged each with this branch and with `main` and compared the conflicts in shared files: - **Same merge path (3):** #9020, #9335 and #9748 extend the single `TargetMerge`. This branch adds conflicts in `CacheKey.hpp`, `DrawLookup.cpp`, `Recompiler.cpp`, `ShaderStageInputInfo.hpp` and `ShaderInputInfoBuilder.cpp`, and its lines fall inside their existing conflicts in `RequestSerializer.cpp`, `SpirvModuleEmitter.cpp`, `State.cpp` and `ShaderMemory.cpp`. - **Adjacent lines (3):** - #11557: the packed refusal in `State.cpp` and the multisampled 4_4_4_4 tests. - #11551: `DrawRegisterKey.cpp` and `ShaderInfoCollector.cpp`. - #6235: its existing conflicts in `State.cpp`, `CacheKey.hpp`, `Recompiler.hpp` and `SpirvModuleEmitter.cpp`. - **This branch's line inside a conflict the PR already has with `main` (7):** #6194, #6223 and #6548 (`libSceAgcDriver.md`); #8004, #9356 and #9387 (`RequestSerializerTests.cpp`); #12662 (`ShaderMemory.cpp`). - **The other 64:** the same conflicts with this branch as with `main`. All 13 are older, so this lands after them, recorded in **Depends on**. I'll rebase onto whichever merges first. ### 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: #6194, #6223, #6235, #6548, #8004, #9020, #9335, #9356, #9387, #9748, #11551, #11557, #12662 - [x] Fixes: #12796 - [x] Unblocks: PPSA26344 #675 - [x] GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 615.78.08, CachyOS Linux (kernel 7.3.0-4-cachyos) - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!12916
No description provided.