fix(shader): read the ancillary render target index from Layer when the draw exports it #5097
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5097"
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 TideOPL on 2026-10-13T11:37:26Z.
What
#4842 made the render target index in the packed pixel ancillary word (bits 16 and up) the constant 0, because no pre-rasterization stage wrote
Layerand reading the unwritten builtin drops the fragment's writes on AMD's Windows driver (#4800). Its description noted that once layered draws exportLayer, those draws need the real value. They do now: a layered draw ORsPA_CL_VS_OUT_CNTLbit 18 into the vertex request (State::layerExports), and #3763 renders layered draws into 3D color targets. A pixel shader in such a draw reads 0 for every layer.Layerwhen the draw exports it, 0 otherwise. The layer field isLayer * LayerExported, whereLayerExportedis a new pipeline specialization constant (PipelineSpecialization::LayerExported), handled like #4031'sRasterPrimitive: the variant records that it reads it (ShaderInfo::layerExported), and the module key and specialization carryShaderPixelStageInfo::layerExported. With the constant at 0 the driver folds the load away, which #4800 showed leaves AMD's writes intact ("gl_Layerloaded but unused: writes land").lowerPackedAncillary(field reads) andComposePackedAncillary(whole-word reads, which composed only the primitive class and the sample index) both use it.DrawDecodesetslayerExportedfromState::layerExportsfor a pixel program that reads the ancillary word. The request serializer writes it from version 23 (main already uses 22 for the tessellation patches per group); older requests readfalse. The shader disk cache format moves to 29.shader.mddebt entry for the packed ancillary word now describes the two cases.Tested
ANYPS5_GPU=Radeon), WinLibs GCC 15.2, Release,BUILD_TESTING=ON, rebased onmain5d7f1ffc1.agc_driver_layered_volume_draw: the layered volume draw again, with a pixel shader that writes(ancillary >> 16) * 0.5to every channel, so the bands of layers 0, 1 and 2 must read 0, 128 and 255. Onmain(with the onelayerExportedline of the test removed) it fails:slice 2 texel (16, 0) channel 0 is 0, expected 128 (the band of layer 1). With this change it passes, also in the_vertexand_vertex_no_gplvariants.pixel_ancillary: rows with the layer exported; field reads and the composed word now include the layer only when exported, and the composed word must useLayerExported.agc_shader_memory: version 23 prefix, version 24 is refused, the flag round-trips, versions 19 to 22 read no flag, a truncated flag is refused. Reading the flag at version 22 fails the test.ctest -E windows_backtrace: 1077 of 1077 pass on5d7f1ffc1(7 skips as onmain).0x164e),agc_driver_relative_ancillary(the #4800 reproduction),agc_driver_pixel_ancillary_wordand theagc_driver_layered_volume_*tests, including the new case, pass.mainrun: the title needs other open PRs to reach gameplay.tools/check_conventions.py --base origin/mainpasses.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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T12:18:10Z.
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.
main)core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppL1846-1847, L1849-1850, L1852, L1962-1967core/shader/recompiler/ControlFlow/src/RequestSerializer.cppL337, L387, L753, L785core/shader/recompiler/PipelineSpecialization.hppL29core/shader/recompiler/Recompiler.hppL152Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-13T12:58:20Z.
Thanks for moving layer to request23. Our staged fork heada5a282 uses your actual
de5279bccommits and latest #5137240411d, rebased on pinned main b0d with authorship preserved, followed by alpha's dither24 field. Upstream tessellation22 remains intact.Independent untouched-author emission confirms twelve canonical23 cases; our registered test-loop bytes match all twelve exactly, including tessellation63/F16/layer combinations. Compatibility20 repetitions, full build and NVIDIA checks pass. AMD outcomes remain disclosed in the maintained alpha report.
The #4451 PR head stays unchanged until #5097/#5137 merge, per review; the final rebase will use the resulting main. Earlier layer22/dither23 proposals were superseded by #4114's upstream22 allocation. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-13T13:41:44Z.
Test report: fixes Epic Mickey: Rebrushed (PPSA15657) on Linux, RX 7600, RADV Mesa 25.2.8.
On main without this PR: the title's levels render with almost no blue. Mean blue in the game area is 0.6 out of 255, while red and green reach 60–70, so the image is yellow-green. The HUD is unaffected. Cause:
PostProcessCombineLUTs.usf,CombineLUTsCommon).What I checked:
3faa9cb40+ this PR (plus #4551 and #5030 for other Mickey issues): the level renders with correct colour, in-level mean RGB about (18, 19, 49), with no errors in a 4-minute scripted session.ctest: 1050 of 1051 passed. The failure isguest_math(abort without output); this PR doesn't touch that code, so I take it to be unrelated.🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:10:06Z.
Review: CHANGES_REQUESTED
Checked the logic (
Layer * LayerExportedin both lowerings, key/specialization plumbing, debt entry): it matches what the tests and the reports from @johnmaia (Epic Mickey, RX 7600, RADV) show.agc_shader_memory,agc_driver_layered_volume_draw,agc_driver_pixel_ancillary_wordandpixel_ancillarypass on the PR merged onto current main.One thing to fix:
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp:389: the newlayerExportedbyte is read atversion >= 22u, but main already writes and reads version 22 (writeRequestwrites22u,patchesPerGroupis read at>= 22u). A version 22 request produced by main has no such byte, so it is misread (the same kind of break as the version 18/19 case fixed in #4031). Move the flag to version 23: bump the written version and the upper bound, read it at>= 23u, and make the legacy-request test inShaderMemory.cpp(the loop over 19..21) cover 22 as well. #5137 and #4451 need to be re-based on that number.Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-13T14:21:26Z.
@AlxcBTW Tag following request
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T14:23:00Z.
@TideOPL thanks for the tag. Sword of the Sea (PPSA25344, UE5) very likely takes the same path: UE's tonemapper builds its colour-grading LUT as a layered 32³ volume draw, and on
mainour scenes come out green-tinted. I'll run this PR on SotS today (RTX 5070, Windows) and post the blue/green ratio of the same frame with and without it.Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-13T14:23:58Z.
Thanks, moved the flag to request version 23 (
de5279bc0): the writer and the upper bound are 23,layerExportedis read at>= 23u, and the legacy loop inShaderMemory.cppnow covers 19 to 22. Reading the flag at 22 fails that test. Rebased on5d7f1ffc1;ctest -E windows_backtrace1077/1077. This matches the layer23 / dither24 order Amoenus proposed for #4451.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:50:06Z.
Review: APPROVED
Re-checked on the head merged onto current main:
Layer * LayerExportedin both lowerings, key/specialization/disk-cache plumbing, request version 23 (>= 23u, versions 19-22 read no flag) and the debt entry.agc_shader_memory,agc_driver_layered_volume_draw,agc_driver_pixel_ancillary_wordandpixel_ancillarypass; without the change the tests don't build. Also confirmed by @johnmaia on Epic Mickey (RADV, RX 7600). The only failure in the scoped run,agc_driver_tessellation, segfaults the same way without this PR. Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T17:58:10Z.
@TideOPL a follow-up from Sword of the Sea, and a correction to my guess above. With this PR ported onto our lab line (RTX 5070 Laptop, Windows):
So I can't claim a fix on SotS. There was no regression either: the session ran normally with the PR in. Sorry for pointing at the wrong cause earlier.