fix(shader): lower the packed pixel ancillary when its extract operands fold after it #1904
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1904"
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 fisherjoey on 2026-10-08T23:11:12Z.
Closes #1903
#1179 is merged; this PR is now one commit (
6b41cf4d) on top of it.What
#1179 lowers the packed pixel ancillary word in one pass after the fold loop, and only when every reader of the word extracts a modelled field. In real shaders the word also has an exec-masked
SelectU32copy.MaskedSelectEliminatorremoves that copy, but it runs afterConstantFolderand the fold does not run again. So while the fold runs, the copy is still a reader, #1179's check refuses the whole word, andShaderInfoCollectorthen throws on the extract that still reads it.When the check refuses the word, each in-range
BitFieldUExtract/BitFieldSExtractthat reads it (directly or throughIdentitycopies) is now rewritten on its own, and the other readers keep the word. When every reader is an extract, #1179's whole-word lowering runs unchanged.Tested
Linux (Nobara 44, GCC 16), RTX 5070 Ti with NVIDIA 595.91.07, and RADV on a Ryzen 5 7600X iGPU with Mesa 26.2.1.
New check
ExtractVectorMaskedCopy()incore/libs/tests/PixelAncillary.cpp: the IR a vectorv_bfe_u32produces (masked offset, clamped count) plus aSelectU32(lane < 16, word, 0)copy of the word. After the fold, the extract must read the Layer (16, 11) or SampleId (8, 4) builtin.ExtractVector()is the same without the copy.pixel_ancillaryExtractVectorpasses,ExtractVectorMaskedCopyfailsctest -R 'agc_|pixel_ancillary' -j1: 225 of 225 on NVIDIA and 225 of 225 on RADV.tools/check_conventions.py --base b4e02e2d: passes.mainall 4 compile. A rerun on this stacked branch is pending.Checklist
main(includes #1179); no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-09T00:36:03Z.
Review: APPROVED
Solid recompiler fix. The root cause is identified precisely (the folder visits the
GetBuiltinbefore the vectorv_bfe_u32extract's operands fold, leaving the ancillary unlowered), and the one-line fix in theBitFieldUExtract/BitFieldSExtractfold case is the right place. The newExtractVectortest builds the exact IR a vector extract emits (masked offset + clamped count) and asserts it lowers to the correct Layer/SampleId builtin, with a main-fails / branch-passes matrix. Tested on hardware (RTX 5070 Ti). Conventions clean.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-09T05:33:57Z.
A real-title data point for this: vkQuake (PPSA99010, the homebrew Vulkan port, through RADV) hits exactly this case and gets past it with this PR.
Its layered blit pixel shader takes the render target index with
v_bfe_u32 v5, v1, 16, 13from the ancillary VGPR. In the IR after folding on currentmain, the extract still readsGetBuiltin PackedAncillary: the offset and count areBitwiseAnd32(16, 0x1f)andUMin32(BitwiseAnd32(13, 0x1f), ISub32(32, ...))in a later block than theGetBuiltin, so they fold only afterlowerPackedAncillaryhas already visited it. Preparing the shader then fails withpacked pixel ancillary input has an unsupported live use, and every present fails.With this PR's commit cherry-picked onto my local test branch (current
mainplus my open RADV PRs), the shader prepares, and with further fixes of mine vkQuake goes on to draw its first frames. Windows 11, RTX 5070 Ti (driver 610.88), WinLibs GCC 15.2.0, Release. I didn't need #1934's select/phi case for this shader.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T14:31:36Z.
Overlap note: #1179 (open since 10-07) also handles a packed ancillary extract whose offset and count fold late. On Stray it doesn't cover this PR's case. After the first fold, the word also has an exec-masked
SelectU32copy as a reader.MaskedSelectEliminatorremoves that copy only later, and #1179's reader check runs once, before that, so it refuses the word. This PR rewrites each in-range extract when it is visited, so the masked copy doesn't block it.Stray, with #1179 in place of this PR: 6 shaders are refused with
unsupported live use (used by BitFieldUExtract 16 11), and one is fatal at a draw. With this PR, all 6 compile. Details on #1179: https://github.com/boykopovar/AnyPS5/pull/1179#issuecomment-6082989392.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:04:55Z.
Checked: build + ctest of libs/Agc/AgcDriver green (
pixel_ancillarypasses); reverting theConstantFolder.cppchange makespixel_ancillaryfail, soExtractVectorMaskedCopypins the fix. Each in-range extract is rewritten on its own when another reader (the maskedSelectU32copy) blocks the whole-word lowering; with only extracts left, #1179's path is unchanged and other readers still throw. Confirmed on vkQuake (PPSA99010, RADV) by @TheAggie.Note: #1934 touches the same function and test file and conflicts with this one; whichever lands second will need a rebase. Merging.