feat(agc): merge partial writes into 4_4_4_4 UNORM color targets #8564
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8564"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 decoratedCoherent: 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:
Draw.cppline 2531 on this branch).The merge is part of the static shader key. Request serializer version is 40 (after
main's 39), shader disk cache format 42 (aftermain's 41) and pipeline journal format 5 (aftermain'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 indocs/dev/debt/libSceAgcDriver.mdanddocs/dev/debt/shader.mdlist them. Among them:Overlaps with open PRs:
sameDecodeline inDrawRegisterKey.cppand 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.Format4_4_4_4UNormcases 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
mainbf2c63f85(committed 2026-10-19 20:52 UTC) with the previous PR stops after 14.5 s withAGC 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, withAGC 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 readsPERSP_CENTERandPOS_Z_FLOATon 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):KILL_ENABLE.agc_driver_packed_unorm4444_multisample_partial_write_testsruns on 2-, 4- and 8-sample targets. The draw states come fromDecodeState. For each sample count:Mutation checks on that test:
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_graphicscover:Coherentimage variableSAMPLE_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 positionPS_ITER_SAMPLEand, apart from the ancillary word, in a draw raised from a one-sample rasterizerEach refusal check fails with its refusal removed. On
maineach of these tests fails at decode, where the 4_4_4_4 target is refused.agc_shader_memorychecks 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, andmain'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 -j4on this branch (with the previous PR below it), before the last rebase ontomain: 1690 of 1691 pass.agc_driver_pass_input_hazardfails, and it fails onmain3 of 3 on this machine too.Vulkan validation: I ran the same focused tests on
mainand on this branch, on the same machine and GPU, throughctest -VwithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_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_serializerandagc_multisample_guest_accessThe new execution tests report only:
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)VUID-VkGraphicsPipelineCreateInfo-renderPass-06053, with the same message thatmain's native depth, pass-order and sample-mask tests reportEarlier, 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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
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_CONTROL0x65040504,CB_COLOR_INFO0x0004171c, write mask 0xf). No host format holds the guest bits of this target (red in 31..21, blue in 9..0, the mirror ofB10G11R11), 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; branchpacked-blend-11_11_10on frankea/AnyPS5, not opened as a PR):TargetMergecarries the target's packing and the color equation ofCB_BLEND_CONTROL, and its mask is 32 bits wide.ColorTarget.partialWriteMaskis 32 bits as well, next to a newmergeBlend. Request serializer 41, shader disk cache 43, pipeline journal 6. A version-40 request still reads as a 4_4_4_4 merge.DecodeStateturns 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.tests/execution/PackedFloatBlend.cppchecks 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 doagc_driver_graphics,agc_driver_packed_unorm4444_partial_writeandagc_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 (main48d61f53bwith 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).
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:TargetMergeSurfaceandEncodeTextureResourcenow describe the array's resident image at the drawn mip, and the shader addresses the view's first slice plusgl_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
maininto that branch meant renumbering your request serializer fields from version 40 to 42, becausemaintook 41 forfloat32DenormPreserve. You'll meet the same conflict when you update this PR, and I'll follow whatever numbering you choose.AI-assisted: yes (Claude Code).
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.
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 currentmain, 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 onmain(from #8563) and are still true, and this PR does not change them. Restore them frommain(the diff againstmainshould 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.