feat(agc): merge partial writes into 4_4_4_4 UNORM color targets #8564

Merged
JAB-dev merged 36 commits from upstream-pr/8564 into main 2026-10-23 21:23:11 +00:00
JAB-dev commented 2026-10-20 16:43:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-20T16:43:52Z.


What

A draw that writes only some channels of a 4_4_4_4 colour target no longer throws. The write is now merged into the stored word, for single-sample targets and for 2-, 4- and 8-sample targets. This PR depends on the previous PR, which adds the 4_4_4_4 target.

The pixel shader reads the word through a driver-supplied storage image of the target under pixel interlock and writes (old & ~mask) | (packed & mask), only for pixels that survive the shader. The image is decorated Coherent: the interlock orders the critical sections, but by itself it makes no write available or visible (Vulkan memory model). The merged target is left out of the draw's attachments, and early fragment tests are forced.

For a multisampled target:

  • Per-sample shading is forced, and each invocation reads and writes its own sample of the target's multisample storage view (the sample index is injected).
  • The target is made storable before its attachment view is taken.
  • Multisampled draws make no draw recipe (Draw.cpp line 2531 on this branch).
  • A shader the guest runs once per pixel may read only inputs that every sample invocation of a pixel sees alike, so each invocation reaches the console's colour and kill decision. Those inputs are centre barycentrics, positions at the centre or upper-left corner, the fixed-point position and the front face. Centre barycentrics are rebuilt at the centre with interpolation functions and fragment shader barycentrics. When the samples are off centre, a device without those throws.

The merge is part of the static shader key. Request serializer version is 40 (after main's 39), shader disk cache format 42 (after main's 41) and pipeline journal format 5 (after main's 4). The journal carries the merged target's write mask, so a replayed pipeline is keyed as the merging draw's. Draws the merge cannot reproduce exactly throw, and the new entries in docs/dev/debt/libSceAgcDriver.md and docs/dev/debt/shader.md list them. Among them:

  • blending, DCC, and shader exports of depth, stencil or a sample mask
  • a kill under late tests in a draw that writes depth or stencil, or once the game has read an occlusion counter
  • a shader that writes guest memory where depth, stencil or depth-bounds tests can reject pixels, or into a multisampled target, where each sample would repeat the write
  • per-pixel inputs that would follow the sample

Overlaps with open PRs:

  • The "write a replace blend into a packed color target without blending" fix turns blending off for any packed target with a ONE/ZERO/ADD colour equation. A 4_4_4_4 target has alpha, so whichever lands second must also require a replace alpha equation or exclude 4_4_4_4.
  • The "preserve raw fragment exports for integer attachments" fix is not needed here (4_4_4_4 has a UNORM output type). It edits the same request-serializer, cache-key and pixel-info lines, so whichever lands second renumbers the version.
  • "keep the guest's sample order where pixel (0,0)'s locations stand in for a 2x2 grid" edits the same request-serializer, cache-key and pixel input info lines. Whichever lands second needs a textual rebase and renumbers the version.
  • "draw one-sample color targets beside a multisampled depth target with sample 0's coverage" edits the same sameDecode line in DrawRegisterKey.cpp and adds a truncated-coverage mode. This PR refuses partial 4_4_4_4 writes under merged coverage only, so whichever lands second must extend that refusal to truncated coverage or test the merge there.
  • "draw a PS_ITER_SAMPLE program once per pixel" (the one-sample depth target and the one-sample color target fixes) merge with this branch without conflicts.
  • If "normalize offset perspective barycentrics after interpolation" lands, the refusal of centre barycentrics without fragment shader barycentrics can be lifted.
  • The previous PR's overlap with the "support packed 16-bit storage images" fix (the same two Format4_4_4_4UNorm cases at the same anchors; whichever lands second drops those lines; no behaviour conflict) is not touched here.

Apart from the packed-16 storage fix's two buffer-format cases, no other open PR implements the same functions.

Arcade Game Zone (PPSA19015) on main bf2c63f85 (committed 2026-10-19 20:52 UTC) with the previous PR stops after 14.5 s with AGC graphics: partial writes of a 4_4_4_4 unorm color target are unsupported. With this PR it stops after 13.7 s, at its first 2-sample merge draw, with AGC graphics: partial writes of a multisampled 4_4_4_4 unorm color target run the pixel shader once per sample, so a shader the guest runs once per pixel cannot read the ancillary word or, unless every sample sits at the pixel centre, centroid, sample-located or pull-model barycentrics, Z, 1/W or a position at the centroid or a sample: they would follow the invocation's sample (SPI_PS_INPUT_ENA 0x402, SPI_PS_INPUT_ADDR 0x402, SPI_BARYC_CNTL 0x1000000, sample 1 location 0xc4). That draw's pixel shader runs once per pixel and reads PERSP_CENTER and POS_Z_FLOAT on a 2-sample rasterizer. Under forced per-sample shading its Z would follow each sample. Where the console evaluates Z for a pixel-rate shader under MSAA has not been measured, so the draw throws. That measurement, or an exact rule for that Z, is what the title needs to get further here.

Tested

Windows 11 x64, GCC 15.2 (WinLibs), NVIDIA GeForce RTX 4070 SUPER, driver 610.88.

agc_driver_packed_unorm4444_partial_write_tests (single sample):

  • Write masks X, X|Z, Y, W, Y|Z, Y|Z|W, Z, X|W and full. The masks and the expected words are hard-coded (golden values: for example X|Z of (0.2, 0.4, 0.6, 0.8) writes the nibbles 0x3090 and Y|Z|W of (0, 1, 0.5, 0.25) writes 0x0F84), not produced by the test's packer; the cases below use the packer.
  • Kill shaders before and after the merging export, and back-to-back draws.
  • A 16-layer overdraw within one draw, which fails 3 of 3 runs without the interlock.
  • Depth rejection, which fails without the forced early tests.
  • With sample counting started, a killing merge under late tests is refused while a merge that kills nothing still draws. This fails without the refusal or without the decoded KILL_ENABLE.
  • Reversing the nibble offsets makes it fail.

agc_driver_packed_unorm4444_multisample_partial_write_tests runs on 2-, 4- and 8-sample targets. The draw states come from DecodeState. For each sample count:

  • A triangle that cuts pixels merges under a later full write.
  • An X merge and a W merge are drawn back to back over crossing triangles, with no read-back between.
  • Every sample is read back through a T# with the target's sample count and checked against the standard sample locations.

Mutation checks on that test:

  • forcing sample 0, removing per-sample shading or reversing the nibble offsets fails
  • keeping only the low bit of the sample index fails once the target has more than two samples
  • giving the merge surface two samples fails

Each merging draw takes the target's storage view before it records, which ends an open render pass and records a shader-write barrier, so two merges never share a pass. Removing that call or that barrier does not make the test fail on this GPU.

Unit tests in agc_driver_graphics cover:

  • decode, and the static shader key (descriptor words excluded)
  • the serializer round trip
  • the SPIR-V shape: one read and one write inside the interlock, through a Coherent image variable
  • the pipeline journal round trip of the write mask
  • the merged-coverage refusal
  • the guest-memory refusal: a merging shader that adds to a buffer counter or to GDS throws under late tests of a draw with a depth, stencil or depth-bounds test. It compiles without such a test, under the guest's early tests and without the merge, and a GDS read compiles. The decode cases include a draw with only depth bounds on, which must report a test that can reject pixels.
  • for 2-sample partial writes: throws when the shader reads SAMPLE_COVERAGE, the ancillary word, or (on a 2-sample rasterizer) a centroid, sample, pull-model, Z or 1/W input or a centroid or sample position
  • the same inputs decode with PS_ITER_SAMPLE and, apart from the ancillary word, in a draw raised from a one-sample rasterizer
  • centre inputs and positions decode
  • centre barycentrics throw without fragment shader barycentrics on a 2-sample rasterizer, and compile in a raised draw whose samples all sit at the centre
  • a merging 2-sample shader that adds to a buffer counter throws

Each refusal check fails with its refusal removed. On main each of these tests fails at decode, where the 4_4_4_4 target is refused. agc_shader_memory checks that the shader key and the serialized pixel info carry the merge, including its depth/stencil write and test flags.

A version 39 request (main's current version) replays with no merge, and main's replay tests of older versions still pass.

The execution tests are skipped on a device without fragment shader pixel interlock, which is likely the case on lavapipe in CI. The multisample test is also skipped without multisampled storage images or sample-rate shading. It skips each sample count the device cannot use as an R16_UINT storage colour target.

Full ctest -j4 on this branch (with the previous PR below it), before the last rebase onto main: 1690 of 1691 pass. agc_driver_pass_input_hazard fails, and it fails on main 3 of 3 on this machine too.

Vulkan validation: I ran the same focused tests on main and on this branch, on the same machine and GPU, through ctest -V with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1. Neither log contains "was not found but was requested by env var". The 23 existing tests report the same VUID ids with the same counts on both:

  • agc_driver_graphics, agc_shader_memory, request_serializer and agc_multisample_guest_access
  • the 5_6_5, 10_11_11, 11_11_10, mip-tail and sRGB8 colour target tests, and the two uint8x4 colour target tests
  • the six multisample readback tests
  • the multisample fill, retirement, pass-order, sample-mask, sample-target and native depth tests

The new execution tests report only:

  • the two pNext ids that every Vulkan test among them reports on main (the layer is the Vulkan SDK 1.3.236 build, older than the 1.4 driver, and does not know the newer structures in those chains)
  • for the single-sample test's depth case, VUID-VkGraphicsPipelineCreateInfo-renderPass-06053, with the same message that main's native depth, pass-order and sample-mask tests report

Earlier, on the render-pass path, the layer with synchronization validation reported 57 feedback-loop and 38 hazard messages before the merged target was left out of the attachments, and none after. It does not check feedback loops under dynamic rendering.

Linux not tested.

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: #8563
  • Fixes: none
  • Unblocks: PPSA19015 #8562
  • GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 610.88, Windows 11
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4939153434 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8564). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-20T16:43:52Z. --- ### What A draw that writes only some channels of a 4_4_4_4 colour target no longer throws. The write is now merged into the stored word, for single-sample targets and for 2-, 4- and 8-sample targets. This PR depends on the previous PR, which adds the 4_4_4_4 target. The pixel shader reads the word through a driver-supplied storage image of the target under pixel interlock and writes `(old & ~mask) | (packed & mask)`, only for pixels that survive the shader. The image is decorated `Coherent`: the interlock orders the critical sections, but by itself it makes no write available or visible (Vulkan memory model). The merged target is left out of the draw's attachments, and early fragment tests are forced. For a multisampled target: - Per-sample shading is forced, and each invocation reads and writes its own sample of the target's multisample storage view (the sample index is injected). - The target is made storable before its attachment view is taken. - Multisampled draws make no draw recipe (`Draw.cpp` line 2531 on this branch). - A shader the guest runs once per pixel may read only inputs that every sample invocation of a pixel sees alike, so each invocation reaches the console's colour and kill decision. Those inputs are centre barycentrics, positions at the centre or upper-left corner, the fixed-point position and the front face. Centre barycentrics are rebuilt at the centre with interpolation functions and fragment shader barycentrics. When the samples are off centre, a device without those throws. The merge is part of the static shader key. Request serializer version is 40 (after `main`'s 39), shader disk cache format 42 (after `main`'s 41) and pipeline journal format 5 (after `main`'s 4). The journal carries the merged target's write mask, so a replayed pipeline is keyed as the merging draw's. Draws the merge cannot reproduce exactly throw, and the new entries in `docs/dev/debt/libSceAgcDriver.md` and `docs/dev/debt/shader.md` list them. Among them: - blending, DCC, and shader exports of depth, stencil or a sample mask - a kill under late tests in a draw that writes depth or stencil, or once the game has read an occlusion counter - a shader that writes guest memory where depth, stencil or depth-bounds tests can reject pixels, or into a multisampled target, where each sample would repeat the write - per-pixel inputs that would follow the sample Overlaps with open PRs: - The "write a replace blend into a packed color target without blending" fix turns blending off for any packed target with a ONE/ZERO/ADD colour equation. A 4_4_4_4 target has alpha, so whichever lands second must also require a replace alpha equation or exclude 4_4_4_4. - The "preserve raw fragment exports for integer attachments" fix is not needed here (4_4_4_4 has a UNORM output type). It edits the same request-serializer, cache-key and pixel-info lines, so whichever lands second renumbers the version. - "keep the guest's sample order where pixel (0,0)'s locations stand in for a 2x2 grid" edits the same request-serializer, cache-key and pixel input info lines. Whichever lands second needs a textual rebase and renumbers the version. - "draw one-sample color targets beside a multisampled depth target with sample 0's coverage" edits the same `sameDecode` line in `DrawRegisterKey.cpp` and adds a truncated-coverage mode. This PR refuses partial 4_4_4_4 writes under merged coverage only, so whichever lands second must extend that refusal to truncated coverage or test the merge there. - "draw a PS_ITER_SAMPLE program once per pixel" (the one-sample depth target and the one-sample color target fixes) merge with this branch without conflicts. - If "normalize offset perspective barycentrics after interpolation" lands, the refusal of centre barycentrics without fragment shader barycentrics can be lifted. - The previous PR's overlap with the "support packed 16-bit storage images" fix (the same two `Format4_4_4_4UNorm` cases at the same anchors; whichever lands second drops those lines; no behaviour conflict) is not touched here. Apart from the packed-16 storage fix's two buffer-format cases, no other open PR implements the same functions. Arcade Game Zone (PPSA19015) on `main` bf2c63f85 (committed 2026-10-19 20:52 UTC) with the previous PR stops after 14.5 s with `AGC graphics: partial writes of a 4_4_4_4 unorm color target are unsupported`. With this PR it stops after 13.7 s, at its first 2-sample merge draw, with `AGC graphics: partial writes of a multisampled 4_4_4_4 unorm color target run the pixel shader once per sample, so a shader the guest runs once per pixel cannot read the ancillary word or, unless every sample sits at the pixel centre, centroid, sample-located or pull-model barycentrics, Z, 1/W or a position at the centroid or a sample: they would follow the invocation's sample (SPI_PS_INPUT_ENA 0x402, SPI_PS_INPUT_ADDR 0x402, SPI_BARYC_CNTL 0x1000000, sample 1 location 0xc4)`. That draw's pixel shader runs once per pixel and reads `PERSP_CENTER` and `POS_Z_FLOAT` on a 2-sample rasterizer. Under forced per-sample shading its Z would follow each sample. Where the console evaluates Z for a pixel-rate shader under MSAA has not been measured, so the draw throws. That measurement, or an exact rule for that Z, is what the title needs to get further here. ### Tested Windows 11 x64, GCC 15.2 (WinLibs), NVIDIA GeForce RTX 4070 SUPER, driver 610.88. `agc_driver_packed_unorm4444_partial_write_tests` (single sample): - Write masks X, X|Z, Y, W, Y|Z, Y|Z|W, Z, X|W and full. The masks and the expected words are hard-coded (golden values: for example X|Z of (0.2, 0.4, 0.6, 0.8) writes the nibbles 0x3090 and Y|Z|W of (0, 1, 0.5, 0.25) writes 0x0F84), not produced by the test's packer; the cases below use the packer. - Kill shaders before and after the merging export, and back-to-back draws. - A 16-layer overdraw within one draw, which fails 3 of 3 runs without the interlock. - Depth rejection, which fails without the forced early tests. - With sample counting started, a killing merge under late tests is refused while a merge that kills nothing still draws. This fails without the refusal or without the decoded `KILL_ENABLE`. - Reversing the nibble offsets makes it fail. `agc_driver_packed_unorm4444_multisample_partial_write_tests` runs on 2-, 4- and 8-sample targets. The draw states come from `DecodeState`. For each sample count: - A triangle that cuts pixels merges under a later full write. - An X merge and a W merge are drawn back to back over crossing triangles, with no read-back between. - Every sample is read back through a T# with the target's sample count and checked against the standard sample locations. Mutation checks on that test: - forcing sample 0, removing per-sample shading or reversing the nibble offsets fails - keeping only the low bit of the sample index fails once the target has more than two samples - giving the merge surface two samples fails Each merging draw takes the target's storage view before it records, which ends an open render pass and records a shader-write barrier, so two merges never share a pass. Removing that call or that barrier does not make the test fail on this GPU. Unit tests in `agc_driver_graphics` cover: - decode, and the static shader key (descriptor words excluded) - the serializer round trip - the SPIR-V shape: one read and one write inside the interlock, through a `Coherent` image variable - the pipeline journal round trip of the write mask - the merged-coverage refusal - the guest-memory refusal: a merging shader that adds to a buffer counter or to GDS throws under late tests of a draw with a depth, stencil or depth-bounds test. It compiles without such a test, under the guest's early tests and without the merge, and a GDS read compiles. The decode cases include a draw with only depth bounds on, which must report a test that can reject pixels. - for 2-sample partial writes: throws when the shader reads `SAMPLE_COVERAGE`, the ancillary word, or (on a 2-sample rasterizer) a centroid, sample, pull-model, Z or 1/W input or a centroid or sample position - the same inputs decode with `PS_ITER_SAMPLE` and, apart from the ancillary word, in a draw raised from a one-sample rasterizer - centre inputs and positions decode - centre barycentrics throw without fragment shader barycentrics on a 2-sample rasterizer, and compile in a raised draw whose samples all sit at the centre - a merging 2-sample shader that adds to a buffer counter throws Each refusal check fails with its refusal removed. On `main` each of these tests fails at decode, where the 4_4_4_4 target is refused. `agc_shader_memory` checks that the shader key and the serialized pixel info carry the merge, including its depth/stencil write and test flags. A version 39 request (`main`'s current version) replays with no merge, and `main`'s replay tests of older versions still pass. The execution tests are skipped on a device without fragment shader pixel interlock, which is likely the case on lavapipe in CI. The multisample test is also skipped without multisampled storage images or sample-rate shading. It skips each sample count the device cannot use as an R16_UINT storage colour target. Full `ctest -j4` on this branch (with the previous PR below it), before the last rebase onto `main`: 1690 of 1691 pass. `agc_driver_pass_input_hazard` fails, and it fails on `main` 3 of 3 on this machine too. Vulkan validation: I ran the same focused tests on `main` and on this branch, on the same machine and GPU, through `ctest -V` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`. Neither log contains "was not found but was requested by env var". The 23 existing tests report the same VUID ids with the same counts on both: - `agc_driver_graphics`, `agc_shader_memory`, `request_serializer` and `agc_multisample_guest_access` - the 5_6_5, 10_11_11, 11_11_10, mip-tail and sRGB8 colour target tests, and the two uint8x4 colour target tests - the six multisample readback tests - the multisample fill, retirement, pass-order, sample-mask, sample-target and native depth tests The new execution tests report only: - the two pNext ids that every Vulkan test among them reports on `main` (the layer is the Vulkan SDK 1.3.236 build, older than the 1.4 driver, and does not know the newer structures in those chains) - for the single-sample test's depth case, `VUID-VkGraphicsPipelineCreateInfo-renderPass-06053`, with the same message that `main`'s native depth, pass-order and sample-mask tests report Earlier, on the render-pass path, the layer with synchronization validation reported 57 feedback-loop and 38 hazard messages before the merged target was left out of the attachments, and none after. It does not check feedback loops under dynamic rendering. Linux not tested. ### 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: #8563 - [x] Fixes: none - [x] Unblocks: PPSA19015 #8562 - [x] GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 610.88, Windows 11 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
frankea commented 2026-10-21 05:48:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-21T05:48:54Z.


@JAB-dev a second use for your interlocked merge: blending into 11_11_10 float color targets. Gran Turismo 7 (PPSA01317) stops on AGC graphics: blending into an 11_11_10 float color target is unsupported, from a plain source-over draw (CB_BLEND0_CONTROL 0x65040504, CB_COLOR_INFO 0x0004171c, write mask 0xf). No host format holds the guest bits of this target (red in 31..21, blue in 9..0, the mirror of B10G11R11), so fixed-function blending is out. Reading the stored word under interlock is exactly what your path does, so I prototyped the blend on top of this PR instead of building a second mechanism.

What the prototype adds (two commits on f5edd537e, the second only adds the target shape to the refusal message; branch packed-blend-11_11_10 on frankea/AnyPS5, not opened as a PR):

  • TargetMerge carries the target's packing and the color equation of CB_BLEND_CONTROL, and its mask is 32 bits wide. ColorTarget.partialWriteMask is 32 bits as well, next to a new mergeBlend. Request serializer 41, shader disk cache 43, pipeline journal 6. A version-40 request still reads as a 4_4_4_4 merge.
  • DecodeState turns a blended (or partial) write into a one-sample 11_11_10 float target into a merge instead of throwing. A ONE/ZERO/ADD equation stays a plain write, as in #7243. Constant color and dual-source factors, and multisampled, mipmapped, volume or array targets, still throw.
  • In the pixel shader the merge unpacks the stored word, blends in fp32 and packs the result with the same toward-zero conversion the export path uses, then applies your mask. The target has no alpha channel, so destination alpha is 1. MIN and MAX ignore the factors, and a ZERO or ONE factor never multiplies, so an infinite operand doesn't turn into NaN.
  • tests/execution/PackedFloatBlend.cpp checks 11 equations, a blended and a plain partial write, a back-to-back chain, and two same-draw overdraws of 16 alternating layers against a CPU reference. On an RTX 4090 (NVIDIA 616.92, Windows 11, WinLibs GCC 15.2) every pixel matches bit for bit, and so do agc_driver_graphics, agc_driver_packed_unorm4444_partial_write and agc_driver_packed_float_color_target.

GT7 result on the RTX 4090, with this prototype plus #7978, #7243, #7256 and #7550 merged locally: the blended draw now reaches the merge, which refuses it in 3 of 3 warm runs (about 3 minutes in; 13 minutes on a cold pipeline cache). GT7's target is a 128x128 cube map, mip 0 of 8, and the draw renders all six faces at once (layers 6, last slice 5). So for this title the merge also needs a layered, mipmapped single-sample target: a storage view of the rendered mip's slices and the fragment's layer index. I haven't started on that, because it touches the parts of your path that are limited to single-level, single-layer surfaces (EncodeTextureResource, TargetMergeSurface). On an older stack (main 48d61f53b with the same fixes), a local switch that writes this draw as a replace instead takes the title to its main menu, so this blend is the last stop before the menu there.

How would you like this stacked: folded into this PR, as a PR on top of it now (Depends on #8563 and #8564), or after it lands? The blend itself is format-independent, so it could cover 4_4_4_4 blending later through the same path.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6309066377 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8564#issuecomment-6309066377). Originally posted by [frankea](https://github.com/frankea) on 2026-10-21T05:48:54Z. --- @JAB-dev a second use for your interlocked merge: blending into 11_11_10 float color targets. Gran Turismo 7 (PPSA01317) stops on `AGC graphics: blending into an 11_11_10 float color target is unsupported`, from a plain source-over draw (`CB_BLEND0_CONTROL` 0x65040504, `CB_COLOR_INFO` 0x0004171c, write mask 0xf). No host format holds the guest bits of this target (red in 31..21, blue in 9..0, the mirror of `B10G11R11`), so fixed-function blending is out. Reading the stored word under interlock is exactly what your path does, so I prototyped the blend on top of this PR instead of building a second mechanism. What the prototype adds (two commits on f5edd537e, the second only adds the target shape to the refusal message; branch `packed-blend-11_11_10` on frankea/AnyPS5, not opened as a PR): - `TargetMerge` carries the target's packing and the color equation of `CB_BLEND_CONTROL`, and its mask is 32 bits wide. `ColorTarget.partialWriteMask` is 32 bits as well, next to a new `mergeBlend`. Request serializer 41, shader disk cache 43, pipeline journal 6. A version-40 request still reads as a 4_4_4_4 merge. - `DecodeState` turns a blended (or partial) write into a one-sample 11_11_10 float target into a merge instead of throwing. A ONE/ZERO/ADD equation stays a plain write, as in #7243. Constant color and dual-source factors, and multisampled, mipmapped, volume or array targets, still throw. - In the pixel shader the merge unpacks the stored word, blends in fp32 and packs the result with the same toward-zero conversion the export path uses, then applies your mask. The target has no alpha channel, so destination alpha is 1. MIN and MAX ignore the factors, and a ZERO or ONE factor never multiplies, so an infinite operand doesn't turn into NaN. - `tests/execution/PackedFloatBlend.cpp` checks 11 equations, a blended and a plain partial write, a back-to-back chain, and two same-draw overdraws of 16 alternating layers against a CPU reference. On an RTX 4090 (NVIDIA 616.92, Windows 11, WinLibs GCC 15.2) every pixel matches bit for bit, and so do `agc_driver_graphics`, `agc_driver_packed_unorm4444_partial_write` and `agc_driver_packed_float_color_target`. GT7 result on the RTX 4090, with this prototype plus #7978, #7243, #7256 and #7550 merged locally: the blended draw now reaches the merge, which refuses it in 3 of 3 warm runs (about 3 minutes in; 13 minutes on a cold pipeline cache). GT7's target is a 128x128 cube map, mip 0 of 8, and the draw renders all six faces at once (`layers 6, last slice 5`). So for this title the merge also needs a layered, mipmapped single-sample target: a storage view of the rendered mip's slices and the fragment's layer index. I haven't started on that, because it touches the parts of your path that are limited to single-level, single-layer surfaces (`EncodeTextureResource`, `TargetMergeSurface`). On an older stack (main 48d61f53b with the same fixes), a local switch that writes this draw as a replace instead takes the title to its main menu, so this blend is the last stop before the menu there. How would you like this stacked: folded into this PR, as a PR on top of it now (Depends on #8563 and #8564), or after it lands? The blend itself is format-independent, so it could cover 4_4_4_4 blending later through the same path. AI-assisted: yes (Claude Code).
frankea commented 2026-10-21 09:56:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-21T09:56:07Z.


@JAB-dev following up on my note above: I've opened the 11_11_10 blend as its own PR, #9020, stacked on this one (Depends on: #8564). Your merge mechanism is credited there as the base it builds on. It also extends the merge to mips and 2D array slices of one-sample targets, which Gran Turismo 7's cube-map target needs: TargetMergeSurface and EncodeTextureResource now describe the array's resident image at the drawn mip, and the shader addresses the view's first slice plus gl_Layer, clamped to the view's last slice. With it, GT7 gets past both stops to its main menu, the World Map and the Used Cars dealer.

Merging current main into that branch meant renumbering your request serializer fields from version 40 to 42, because main took 41 for float32DenormPreserve. You'll meet the same conflict when you update this PR, and I'll follow whatever numbering you choose.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6313175198 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8564#issuecomment-6313175198). Originally posted by [frankea](https://github.com/frankea) on 2026-10-21T09:56:07Z. --- @JAB-dev following up on my note above: I've opened the 11_11_10 blend as its own PR, #9020, stacked on this one (`Depends on: #8564`). Your merge mechanism is credited there as the base it builds on. It also extends the merge to mips and 2D array slices of one-sample targets, which Gran Turismo 7's cube-map target needs: `TargetMergeSurface` and `EncodeTextureResource` now describe the array's resident image at the drawn mip, and the shader addresses the view's first slice plus `gl_Layer`, clamped to the view's last slice. With it, GT7 gets past both stops to its main menu, the World Map and the Used Cars dealer. Merging current `main` into that branch meant renumbering your request serializer fields from version 40 to 42, because `main` took 41 for `float32DenormPreserve`. You'll meet the same conflict when you update this PR, and I'll follow whatever numbering you choose. AI-assisted: yes (Claude Code).
JAB-dev commented 2026-10-21 19:47:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-21T19:47:43Z.


Stacked on top as your 11_11_10 blend PR is what I'd like, thanks for the prototype and the testing. Keeping it separate means each PR stays one topic. I've merged current main into the packed 4_4_4_4 partial-writes PR, so the numbering is now: request serializer 43 (main's sampleOrder stays at 42 and the merge fields follow it), shader disk cache 45, pipeline journal 7. Layered and mipmapped targets as a follow-up in your PR is fine, and 4_4_4_4 blending can use the same path later.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6325043403 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8564#issuecomment-6325043403). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-21T19:47:43Z. --- Stacked on top as [your 11_11_10 blend PR](https://github.com/boykopovar/AnyPS5/pull/9020) is what I'd like, thanks for the prototype and the testing. Keeping it separate means each PR stays one topic. I've merged current main into [the packed 4_4_4_4 partial-writes PR](https://github.com/boykopovar/AnyPS5/pull/8564), so the numbering is now: request serializer 43 (main's sampleOrder stays at 42 and the merge fields follow it), shader disk cache 45, pipeline journal 7. Layered and mipmapped targets as a follow-up in your PR is fine, and 4_4_4_4 blending can use the same path later.
adriadam10 commented 2026-10-23 19:32:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-23T19:32:55Z.

Review: CHANGES_REQUESTED


Reviewed the full diff (driver, recompiler, serializer/cache/journal versions, refusals and their tests); the Build run on this head is green. One thing blocks the merge:

  • docs/dev/debt/libSceAgcDriver.md, "Packed 16-bit textures" entry: merged with current main, this branch deletes the sentences "Storage images use compatible R16_UINT views with the buffer UNORM store conversion ...; quantization uses nearest even and maps NaN to zero. Rounding ties and NaN handling for packed stores have not been checked on AMD or PS5 hardware." They are on main (from #8563) and are still true, and this PR does not change them. Restore them from main (the diff against main should then touch that entry not at all).

Nothing else to change. Once that line is back and CI is green on the new head this can merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5633499777 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8564#pullrequestreview-5633499777). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-23T19:32:55Z. **Review:** CHANGES_REQUESTED --- Reviewed the full diff (driver, recompiler, serializer/cache/journal versions, refusals and their tests); the Build run on this head is green. One thing blocks the merge: - `docs/dev/debt/libSceAgcDriver.md`, "Packed 16-bit textures" entry: merged with current `main`, this branch deletes the sentences "Storage images use compatible R16_UINT views with the buffer UNORM store conversion ...; quantization uses nearest even and maps NaN to zero. Rounding ties and NaN handling for packed stores have not been checked on AMD or PS5 hardware." They are on `main` (from #8563) and are still true, and this PR does not change them. Restore them from `main` (the diff against `main` should then touch that entry not at all). Nothing else to change. Once that line is back and CI is green on the new head this can merge.
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!8564
No description provided.