feat(shader): give reads the masked-select pass keeps the whole pixel ancillary word #4031
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4031"
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 AlxcBTW on 2026-10-11T21:36:32Z.
What
Refs #2548 and #3504. With this change a select that the masked-lane walk keeps no longer stops the recompile, because every read the walk keeps gets the whole word. That lets #3550's walk budget stay low without breaking titles that need the select gone for the ancillary lowering (Stray's
0x2013010000, see #3504).A select the masked-lane walk can't drop still stops the recompile on #3279. Palworld's
0x1b40e5c000is one (Rohan03x on #2548: the kept select is reached through aReadFirstLane, which reads other lanes), and so are Minecraft Dungeons II's0x190095e900and0x190095fc00. With this commit every read the walk keeps gets the whole word:RasterPrimitiveOf);The layout is from the RDNA 3/3.5 ISA guides. The GCN register guides agree for layers below 2048, Mesa reads sample and layer from those bits, and AMD's LLPC reads the prim type from bits 1:0 with the same encoding. Nobody has checked it on gfx1013; TechnicalDebt.md says so.
Where the primitive class comes from (owner's call)
IrBindingLayoutinDescriptorBinding.hpp), and no fragment builtin can tell a rect list (drawn as tessellated triangles) from a triangle. The smallest run-time variant adds one dword to that block in shaders that read the class, and patches it per draw fromGraphics::Statethe wayShaderResourcespatches guest buffer offsets (pushBytefor push constants,dataBytefor the ShaderData buffer). The module key, result memo, draw key and request format could then stay as onmain. But the shader-data layout changes (IrBindingLayout, disk cache format), the block spills to the ShaderData buffer one dword sooner, and every pixel wave loads the class instead of using a constant.VkSpecializationInfofromGraphics::State, whose pipeline key already holds the topology and rect-list state. The request format, module key, result memo and draw key would then stay as onmain. Prepared modules would have to leave that one constant open (buildSpecializedModulerequires every SpecId today), and the GPL fragment-library key would need the class for shaders that read it.Tested
maind592d54e1is merged into the branch (no rebase). The head ise24413c44.mainwrites request version 17 withstencilRefExportEnableas its last pixel field, sorasterPrimitiveis written after it and read from version 18: a version 17 request frommainstill reads, andShaderMemory.cppchecks the version 18 prefix, rejects 19 and truncates over all 20 trailing pixel bytes. The disk cache format is 28. The conflict resolutions match @blawesom's rebase (771c00783) except for that version.#4150, merged since, added
agc_driver_relative_ancillary. Its last case expected a whole-word read throughv_movrelsto be refused; #4150 notes that this PR composes that word. The one commit on top of the merge turns that case into a check of the composed word: the shader converts the word to float and exports it, and a triangle draw's word is 2, so the pixel is 255, with and without the implicit position inputs in front of the ancillary VGPR. In TechnicalDebt, the relative addressing entry no longer says that whole-word uses throw.agc_driver_pixel_ancillary_word,agc_driver_relative_ancillary,agc_driver_graphics,agc_driver_dual_source_blendandagc_driver_alpha_to_coveragepass.relative_ancillaryfailed on the bare merge (77f0a568b), before the test update, with "an unsupported ancillary word was accepted".e24413c44merged into the fork'smain: Linux passes 968 of 968 (lavapipe; 43 skipped for features lavapipe lacks), includingagc_driver_pixel_ancillary_word,agc_driver_relative_ancillary,pixel_ancillaryandagc_shader_memory. Windows passes 974 of 974, with the GPU tests skipped for lack of a device.ctest -E '^agc_driver|^video_out|^guest_video': 618 of 619 pass, includingpixel_ancillary,agc_shader_memoryandagc_shader_disk_cache.log_macrosfails there on every branch and passes in CI.tools/check_conventions.py --base origin/mainpasses.Earlier, rebased onto
maina11c8f7f7as one commit (db92ece3c):agc_driverset passes 296 of 297.agc_driver_emulated_color_comparefails the same way onmain(sRGB sampling refusal).b58c0428) onmain, tested by @ThatsLeo on Intel Arc (Mesa 26.2.3) and lavapipe (comment): all 43 Stray (PPSA02101) requests compile at a 32x budget and passspirv-val --target-env vulkan1.3. The two slow shaders of #3504 take 1.0 and 2.2 s, and0x2013010000compiles at every budget.Before the rebase (on
mainplus #3279):Windows 11, RTX 5070 Laptop GPU (NVIDIA driver; the AMD iGPU is hidden from the Vulkan loader):
ctest -j4: 764 of 766 pass.guest_filesystemfails the same way on a tree without this commit, andguest_sce_nettimed out under load and passes on its own.agc_driver_pixel_ancillary_wordexports the word from a draw and reads back 2, 3 and 1 for the triangle, rectangle and line classes. The draw itself is a triangle and the request carries the class, asDrawDecodesets it; the test checksRasterPrimitiveOfon its own. It also compiles one whole-word shader and one that reads only the sample field (v_bfe_u32 v20, v0, 8, 4) for the three classes: the whole-word shader gets three modules of 629 SPIR-V words, and the sample-only shader shares one module of 616 words.pixel_ancillaryandagc_driver_pixel_ancillary_wordfail with the oldunsupported live userefusal. If the module key is keyed on ANCILLARY_ENA instead of on the read, the module check fails (sample field only: a line or rectangle draw built its own module).tools/check_conventions.pypasses.0x1b40e5c000compiled in Rohan03x's offline replay.0x20b8770000is refused onmain1e8fff68and with #3391 added, and compiles with this head (74,245 SPIR-V words). In game the per-frame skips of that draw are gone, with no GPU hang in two runs (2.5 and 4 min). Other draws on that frame are still skipped, so this shader's output is not checked yet.agc_driver_pixel_ancillary_wordpasses there. The one failure isagc_unit_shadow, which fails on this base without the change too (#1429, fixed onmainby #3226).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)0x2013010000(#3504; Game bring-up #2461 is PPSA02100)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T13:34:58Z.
Rebase handoff — rebased onto current
main, authorship unchanged.Four files conflicted, all the additive-field shape:
mainlandedstencilRefExportEnablewhere this PR threadsrasterPrimitivethrough the pixel-stage info, serializer and tests. The resolution keeps both — both fields, both serialization entries, both round-trip checks, and both test families (main's StartingQuad series and this PR's whole-word series).Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesTo pick it up:
Head is
771c00783.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T17:04:49Z.
@blawesom thanks for the rebase and for running the whole suite on RADV.
The branch now has
mainmerged into it rather than rebased, so its history stays as it was. The conflicts are resolved the way you did it: both fields, both serializer entries, and both test families (the StartingQuad series and the whole-word series).The one difference is the request serialization version.
mainalready writes version 17 withstencilRefExportEnableas the last pixel field. IfrasterPrimitiveis also read from 17, a version 17 request written bymaincomes up one byte short: the reader expects the primitive class after the stencil flag and fails with "truncated data". This head writes version 18, reads the stencil flag from 17 and the primitive class from 18. TheShaderMemory.cppchecks follow: theNVNQQRIAAAA=prefix, rejection of version 19, and truncation over all 20 trailing pixel bytes, so the primitive class byte is covered too. The disk cache format stays 28.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T17:49:49Z.
Verified your merged head (
e24413c44): builds, conventions pass, and the full suite is 958/958 on RADV — including the serializer round-trips and the new version-18 coverage.And credit where due: the version bump is a catch my rebase missed. I merged both fields but kept the primitive class read at version 17 — which is exactly the one-byte-short truncation you describe for main-written version-17 requests. Writing 18 and splitting the reads (stencil from 17, primitive from 18) is the right wire behavior, and the
NVNQQRIAAAA=+ version-19 rejection + 20-byte truncation coverage settles it. From my side this is merge-ready.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-12T22:15:50Z.
Ran this on AMD hardware, since the GPU tests in CI run only on lavapipe: Windows 11 (26300), Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON. Headdd8403112merged ontomain584cc4c57.GPU tests (
ctest -R '^agc_|pixel_ancillary' -j 1, test shader cache emptied first):main584cc4c57agc_driver_relative_ancillarymain+ this PRagc_driver_relative_ancillary,agc_driver_pixel_ancillary_wordagc_driver_pixel_ancillary_wordis this PR's new test, and it fails 5 runs of 5:The target is filled with
0xffbefore the draw, so NaN means pixel (0, 0) was never written. The draw didn't land there, as opposed to writing a wrong word.With
APS5_NO_PIPELINE_LTO=1it still fails 3 of 3, but not always on the same case: twice on "ANCILLARY alone, triangle" and once on "ANCILLARY after the perspective center, rectangle". Each time the pixel is unwritten.APS5_NO_GPL=1andAPS5_SPIRV_OPT=nonegive the triangle failure too.agc_driver_relative_ancillary(from #4150) already fails on plainmainon this GPU, 3 of 3:wave 32 packed read/relative ancillary draw produced an incorrect pixel: 64. That test fills its target with0x40(64) before drawing, so this is the same signature: the draw left the pixel unwritten. Both tests draw with a pixel shader that reads the ancillary VGPR, and on this GPU those draws leave pixels unwritten onmaintoo. So it doesn't look specific to this PR. I'll report themainfailure separately.Other tests:
ctest -E '^agc_|pixel_ancillary' -j 4: 572/572 with this PR.Titles. Seven homebrew titles that render on
mainwere run for 60 s each, with and without this PR: Stremio Plus, Capy Mobile, DriftCheck, EVO Player, Jelly5, Emby5 and OpenRCT2. All seven run the full 60 s either way, with no stop and no new error. None of them reaches the shaders this PR is for, so this only checks for regressions.I haven't looked into why the draw leaves pixels unwritten on this GPU. I can run a diagnostic build or more cases if that helps.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T22:51:54Z.
@LeandroLP23 thanks for running both tests on the 860M, and for noticing that the
mainfailure has the same signature. That pointed straight at the cause.It is not the sample index and not invalid SPIR-V from this PR. It is AMD's shader compiler (LLPC) programming the position exports inconsistently when a pixel shader reads
gl_Layerand the vertex shader writesgl_ClipDistancebut notgl_Layer.Both failing draws read the reconstructed ancillary word, so their pixel shaders read
SampleIdandLayer. Onmain, the packed read inrelative_ancillaryalso builds the whole word from both. Since #3878 (the all-zero position clip), every vertex shader AnyPS5 emits that exports a position also writesgl_ClipDistance[0]. With that pair, the 2025 LLPC:exp pos1 off, off, v0, off, only z) and moves the clip distance topos2;SPI_SHADER_POS_FORMATandPA_CL_VS_OUT_CNTLfrom the vertex shader's own outputs: two position exports, no misc vector, the clip distance vector atpos1, andCLIP_DIST_ENA_0andCULL_DIST_ENA_0set.So the rasterizer takes clip distance 0 from
pos1.x, which the shader never writes. It holds whatever was left in the position buffer, and when that value is negative the triangle is clipped or culled. That is why the target keeps its fill value, and why the failing case changes between runs.How I checked it, all on the CPU:
MESA_SPIRV_DUMP_PATH).spirv-val --target-env vulkan1.3passes on every module, and the validation layers on lavapipe report nothing for either test.SampleIdturns on sample shading.Layerreads 0 when the pre-rasterization stage doesn't write it. ThegeometryShaderandsampleRateShadingfeatures are enabled. The interface has no user varyings.amdllpcthat ships in Radeon GPU Analyzer:amdllpcfrompos0,pos1(layer, z only),pos2(clip)pos1pos0,pos1(clip)pos1With 2.13, the same clip distance with a pixel shader that reads only
gl_SampleID, or no built-in at all, compiles consistently. Only thegl_Layerread adds the extra export. In the public LLPC source (April 2025),LowerInOut.cppforcesuseLayerfor the pixel shader's sake, whileRegisterMetadataBuilder.cpponly looks atbuiltInUsage.vs.layer. Going by the version numbers, your driver (32.0.13058) comes from the same 24.30 branch as Adrenalin 25.3 and 25.4, which is before the change.A minimal repro outside AnyPS5: the vertex shader writes
gl_Positionandgl_ClipDistance[0] = 0.0but notgl_Layer, the fragment shader writesvec4(float(gl_Layer), 0.0, 0.0, 1.0), and a full-screen triangle draws into a target pre-filled with a sentinel. On an affected driver some or all pixels keep the sentinel. Dropping either the clip distance or thegl_Layerread makes it correct.One check would confirm it on your machine. In
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp, inDefineOutputs, changeif (exportsPosition && (stage == IrShaderStage::Vertex || stage == IrShaderStage::TessellationEvaluation))toif (false && exportsPosition && (stage == IrShaderStage::Vertex || stage == IrShaderStage::TessellationEvaluation)). That drops the zero-position clip distance. Rebuild and runctest -R "relative_ancillary|pixel_ancillary_word" --output-on-failurea few times. If both pass on every run, this is the cause.agc_driver_zero_position_vertexwill fail with that patch, which is expected. A current Adrenalin driver should pass without the patch, but I could only check the compiler from RGA, not the Windows driver itself.If it confirms, AnyPS5 can keep clear of this on older drivers. When the pre-rasterization stage doesn't write
Layer, the layer field is 0 by the spec, so the pixel shader doesn't need to readgl_Layerat all. That would be a separate PR.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-12T23:27:59Z.
@AlxcBTW the AMD failure above comes from reading the unwritten
Layerbuiltin (#4800). #4842 replaces the render target index field with 0 inlowerPackedAncillary. With #4842 merged under this branch and the same 0 at your whole-word read (insertBuiltin(..., StageInputKind::Layer)shifted by 16),agc_driver_pixel_ancillary_wordpasses 3/3 on the Radeon 860M. Whichever of the two merges second needs that line and thepixel_ancillarycases reconciled; happy to do it on my side if this one goes first.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T23:52:42Z.
Three things on dd840311 before the question of the unknown bits:
mainreadstarget.vertexSubgroupsat version 18 since #4470 (RequestSerializer.cpp:793). This head readsrasterPrimitiveat 18 as well (:387), so a version-18 request written bymainis read one byte short. It needs 19, with the prefix and reject-version checks inShaderMemory.cppmoved; it is the same collision you caught at 17.ComposePackedAncillarystill insertsGetBuiltin Layer << 16, soagc_driver_pixel_ancillary_wordfails on the 860M as LeandroLP23 showed. #4842 makes that field 0 onmain; it should go in first and this take the same 0.mainindocs/dev/debt/shader.md.On the word itself nothing has changed since #1179: bits 2-7, 12-15 and 29-31 are zero by argument, not by measurement, and that is the rule adriadam10 set there, so it is his or the owner's call and not mine.
Kena's remaining shader may not need the word at all.
(used by SelectU32 1065353216 ?)is a select between1.0fand the register, which reads like the VGPR reused for a float with the word left on the other arm, and that is a case for one more rule in the masked-select pass. @fma-rc could you attach the.reqfor0x20b6440000, or the IR around that select? If a rule covers it, Kena compiles exactly and this PR is left with the shaders that really export the word, if there are any.Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-13T00:14:57Z.
@oneandonlydean here is the request for
0x20b6440000: https://github.com/fma-rc/AnyPS5/raw/evidence/kena-shader-20b6440000/shader_20b6440000.reqIt is the file
APS5_DUMP_SHADERSwrote, unchanged: 936 code words, 30 user data words, 2 memory regions, wave64.agc_shader_replaybuilt frommaind38d98bc8(with one unrelated local change in the driver's texture code) still stops on it withpacked pixel ancillary input has an unsupported live use (used by SelectU32 1065353216 ?).I have no IR dump at the failing point, the tool only prints the instruction listing for it. I can post that listing, or the other 16 Kena requests, if either helps with the select rule.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T00:40:08Z.
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.cppL1811, L1816core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppL117core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cppL72core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppL108core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppL1811, L1813-1814, L1816, L1905-1906core/shader/recompiler/ControlFlow/src/RequestSerializer.cppL328, L377, L739, L770core/shader/recompiler/Recompiler.hppL144docs/dev/debt/shader.mdL100-102Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:58:15Z.
Pushed the rebase and one commit on top (
c52321fab5), your two commits kept as they are:docs/dev/debt/shader.md.vertexSubgroupsat 18, so a version-18 request from main was misread (RequestSerializer: truncated data); there is a test with one.primitive | (SampleId << 8), without theLayerread, since draws render to one layer. The field-extract path still reads it; that is #4842, which goes on top of this.ctest -R "agc|shader"is 462/462 on Linux/NVIDIA, and @fma-rc's request for0x20b6440000fails on main with theSelectU32refusal and recompiles with this (71528 words). Not run on AMD or Windows here; full build is running.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T02:23:14Z.
@LeandroLP23 thanks for #4842, and for confirming
agc_driver_pixel_ancillary_word3/3 on the Radeon 860M with it merged under this branch. @oneandonlydean thanks forc52321fab.With that commit, #4031 reads the render target index field (bits 16+) of the whole composed word as the constant 0, with the same reasoning as #4842: no pre-rasterization stage writes Layer today, and reading it breaks the position exports on AMD's Windows driver (#4800). The
pixel_ancillarywhole-word cases expect 0 for the field.The extract path in
lowerPackedAncillarystill reads Layer on this branch; that's the part #4842 changes. Whichever of the two merges second only has to reconcile that one line inConstantFolder.cppand the matching test cases. If #4842 goes first, we're happy to do that on our side.AI-assisted: yes (Claude Code)