feat(recompiler): pixel ancillary word used whole #1179
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1179"
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 MichonGoddijn231849 on 2026-10-07T16:44:25Z.
What
The packed pixel ancillary VGPR may reach its sample-number and render-target-index extracts through a move or a select, and those extracts may only get immediate offsets and counts late in folding (GTA V; data from other titles in this thread). After the fold pass, such a word is lowered when every reader, through
Identityor a select's value operand, is aBitField(U/S)Extractwith an immediate offset and count inside the sample field [8,12) or the RTA field [16,29): each extract becomes a directSampleId/Layerread. Any other reader (an unmodelled bit, a whole-word compare, a store, a count of zero, a phi) keeps the word live and the shader is refused as onmain. No bit outside the two modelled fields is ever produced as zero.core/libs/tests/PixelAncillary.cppevaluates the lowered IR against the full packed word with the unmodelled bits set, on edge rows (sample 0 and 15, layer 0 and 0x1fff, both facings), including a late-folded extract and select chains, and checks that reads of unmodelled bits throw, directly and through a select. The inferred layout and the unmodelled fields are listed under Unknown function info in TechnicalDebt.md.Tested
Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB, MinGW-w64 GCC 15.2.0.
pixel_ancillarypasses and fails against the previous version of this PR (the silent-zero cases) and againstmain(the late-folded and select cases); theagc_shader_*,agc_spirv_moduleandagc_drivertests pass.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-10-07T17:01:34Z.
Data point from The Smurfs Dreams (PPSA21607, Unreal Engine) on Linux with an AMD GPU: about 2000 draws per run were skipped with
packed pixel ancillary input has an unsupported live use, mostly 64-instance layered draws into the 64x64x64 and 32x32x32 lighting volumes. With this PR all of them compile: the 8 dumped requests recompile withagc_shader_replay, the game logs no more such skips, andpixel_ancillarypasses.One observation in case it's useful: in these shaders the "other" use is actually an exact render target index extract,
BitFieldUExtract %anc, 16, 11in the final IR. It isn't lowered becauseConstantFolder::Foldis a single pass in block order. When theGetBuiltinin the entry block is visited, the extract's offset and count are stillBitwiseAnd32(16, 31)andUMin32(...)in the next block, and they fold only afterwards. Locally, callinglowerPackedAncillaryfrom theBitFieldUExtract/BitFieldSExtractfold case once offset and count are immediate also lowers them, as a directgl_Layerread without the rebuilt word. The result is the same here, so I'm leaving it as a note rather than opening a separate PR.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T17:38:45Z.
@Pacuka thanks for testing it on The Smurfs Dreams. You're right about the cause:
ConstantFolder::Foldis a single pass in block order, so an exact render target index extract whose offset and count only fold in a later block reacheslowerPackedAncillarytoo late and takes the rebuilt-word path. The result is the same, as you say, so I'll leave it as is here. Lowering from theBitFieldUExtractfold case once both operands are immediate would be a clean follow-up.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T08:42:58Z.
Review: CHANGES_REQUESTED
Checked: build, ctest (424/424,
pixel_ancillarypasses), and the new test fails without the change. Linux/Windows CI green. Findings:ConstantFolder.cpp:242-258: the rebuilt word zeroes every bit except sample number and RTA index. The word carries other fields too (the RDNA 3.5 ISA, ANCILLARY_ENA/VGPR21, lists Prim Type [1:0], VRS rate X [3:2] / Y [5:4] and Eye_id [7]; we couldn't get the RDNA 2 table, but the point holds for any bit outside the two modelled fields). Any later use that reads those bits (a field extract after the select/mov, a compare, a store) now silently gets 0 wheremainthrew. This is the plausible-but-wrong result we reject (exact or throw).BitFieldUExtract %anc, 16, 11; LEGO Horizon: offset/count only fold later) shows the real uses are extracts that fold too late. Lowering from theBitFieldUExtractfold case once offset/count are immediate, or following the word through the select/mov to its extracts, keeps the exact path and leaves everything else throwing. If a whole-word use must stay supported, restrict it to words whose every transitive use is an extract of the modelled fields, and throw otherwise.core/libs/tests/PixelAncillary.cpp:54-66:Whole()only pins the IR shape (OR of two shifts). Please pin values: an execution/evaluation test with edge rows (sample 0/15, layer 0/max, and a use that reads an unmodelled bit that must throw).docs/dev/TechnicalDebt.mdunder "Unknown function info" (not at the end of the section).Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-08T15:47:21Z.
Thanks, reworked along the lines you suggested:
Identityor a select's value operand and is an extract with immediate offset and count inside the sample or RTA field; each such extract becomes a directSampleId/Layerread. Any other reader keeps the word live, so the shader is refused as onmain. Lowering at the end of the pass covers the extracts whose offset and count fold late (the Smurfs Dreams and LEGO Horizon cases).pixel_ancillarynow checks values: it evaluates the lowered IR against the full packed word with unmodelled bits set, on sample 0/15, layer 0/0x1fff and both facings, and checks that unmodelled-bit reads throw, directly and through a select. It fails against the previous version of this PR and againstmain.GTA V has not been re-run with the rework yet; the description says so.
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T14:31:27Z.
I tested this PR on Stray (PPSA02100 v1.05, Unreal Engine 4). Stray has 32 pixel shaders that read the packed ancillary word, and this PR doesn't get any of them through.
Setup: Linux (Nobara 44, kernel 7.2), RTX 5070 Ti, NVIDIA 595.91.07. Base is
main1be6f9f1plus the other fixes Stray needs to reach its first draws. That base includes my #1904 and #1934 reverted and this PR merged, so the ancillary handling is this PR alone.pixel_ancillarypasses.Late-folded extract (6 shaders, e.g. 0x200e360000). The shader reads the render target index with
v_bfe_u32 v4, v4, 16, 11and then reuses v4. It is refused:After the first
ConstantFolder::Foldthe word has two readers: the extract, already#16, #11and inside the RTA field, and aSelectU32that is the exec-masked copy of v4.MaskedSelectEliminatorremoves that select later in the pipeline, but the reader check here runs once, before that pass. So it follows the select's value operand, finds readers that are not in-range extracts, and refuses the word. The check never runs again after the select is gone. One of these shaders is used at a draw, so the run ends there instead of only deferring it.Word carried through a phi (26 shaders). Here v4's old value reaches
Phi,BitCastF32U32and float math in lanes that skip a later write. That is out of scope by design in this PR (phi and whole-word readers are refused), so these are refused as expected:For the first case, either of these would work:
MaskedSelectEliminator, or run it a second time after it, so exec-masked copies are gone before the readers are classified;SampleId/Layeras it is visited, regardless of the word's other readers. Any remaining reader then keeps the word live and is refused as now.The second is what #1904 does. With #1904 merged, these 6 shaders compile and the run gets past them. #1934 covers the phi case by rebuilding the word from
SampleIdandLayer, with the other bits read as 0. That trades exactness for coverage, so it's a separate decision from this PR. I'm happy to fold #1904 into this PR, or rebase it on top of this one, whichever you prefer.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T14:39:41Z.
Thanks for testing it on Stray and for the analysis. I would prefer #1904 rebased on top of this PR as its own PR: it keeps this one small, and the rewrite-each-extract approach is your work. The phi case (#1934) can then be decided separately, as you say.
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T15:20:57Z.
Done: #1904 is now rebased on this PR as one commit (46e17bfe, Depends on #1179).
It turns out the rebase is needed. On Stray (PPSA02100), b4e02e2d alone doesn't compile the real S5a shaders. 0 of 4 replay offline, and in game all 6 stay deferred and the draw fails. With #1904's change, all 4 compile.
The real shaders have an exec-masked SelectU32 copy of the ancillary word, which is still a reader when ConstantFolder runs. MaskedSelectEliminator removes that copy, but only after the fold, and the fold doesn't run again. Your one-time reader check sees the copy and refuses the whole word, and ShaderInfoCollector then throws on the extract that's still reading it.
#1904's ExtractVector test missed this because it had no masked copy. The new ExtractVectorMaskedCopy case adds one (an extract plus a SelectU32(lane < 16, word, 0) copy). It fails on b4e02e2d and passes with the change.
Your whole-word lowering is unchanged. Only when the reader check refuses the word does the change rewrite each in-range extract on its own, directly or through Identity copies, and leave the masked copy alone. pixel_ancillary and the agc_ tests pass on NVIDIA and RADV. #1934 stays against main for now.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T22:11:49Z.
Rebased onto current
main(e51d4e1f), headd8b1ad71. The only conflict was a neighbouring line inTechnicalDebt.md; the code is unchanged. @fisherjoey #1904 sits on the old head, so it needs the same rebase to drop the two old commits from its diff.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:26:45Z.
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/tests/PixelAncillary.cppL42-43, L58-59core/shader/recompiler/Optimization/src/ConstantFolder.cppL215-221docs/dev/TechnicalDebt.mdL43Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:56:49Z.
Review: APPROVED
Checked: build and ctest green (548/548,
pixel_ancillarypasses), and the new test fails without the change. The reader check (throughIdentity/ select value operand, immediate offset and count inside the sample or RTA field, count 0 and the unmodelled bits refused) matches the description, and the TechnicalDebt line is in the right section. Merging once CI is green.Not covered here, as discussed in the thread: the exec-masked select copy that Stray hits is handled by #1904, which is stacked on this one; #1934 will need a rebase on its test file afterwards.
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-10T00:48:59Z.
Done: #1904 now sits on your
d8b1ad71, with our change as one commit on top (6b41cf4d). pixel_ancillary, including ExtractVectorMaskedCopy, and the agc_ tests pass on it.AI-assisted: yes