fix(shader): packed pixel ancillary as SampleId and Layer, gl_Layer via Geometry, Z export formats #295
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/295"
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-01T21:58:17Z.
What
Split out of #167.
gl_SampleIDandgl_Layerreads, instead of failing withpacked pixel ancillary input has an unsupported live use.gl_Layer: a pixel shader reading it needs the Geometry capability instead of ShaderLayer and SPIR-V 1.5. The Geometry capability is available whenever the geometryShader feature is, and the device enables sampleRateShading, geometryShader and shaderClipDistance when available.SPI_SHADER_Z_FORMATs and 32_ABGR are accepted together with the depth and sample-mask export enables.Tested
Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.
main.ctest: all tests 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🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-03T19:50:46Z.
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.cppImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:39:30Z.
Thanks for splitting this out of #167. The sample id and layer fields match what Mesa unpacks (
ac_nir_lower_intrinsics_to_args.c: bits 8 to 11 and 16 to 28), and Geometry is the right capability for a fragment Layer input.One thing I'd change: in
lowerPackedAncillary, a use that isn't a bit-field extract inside one of those two fields getsSampleId << 8 | Layer << 16. That reads 0 for the other bits (Mesa takes the VRS rates from bits 2 to 5, for example), where main threwunsupported live use. Could that path keep throwing, so only the extracts that map exactly are lowered? A recompiler test with an extract of each field, plus a whole-register use that is still refused, would cover it.Also, #375's validator change needs the
geometryShaderandsampleRateShadingenables this PR adds to VulkanDevice (main doesn't enable them), and this PR's Geometry and SampleRateShading modules need #375 to pass validation. I'd land this one first and addDepends on #295to #375.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-04T08:27:23Z.
Done in cd491902.
lowerPackedAncillarynow lowers only bit-field extracts (signed or unsigned, constant offset and count) that lie entirely inside bits 8..11 or 16..28. They are rebased ontoSampleIdorLayer. Every other use keeps reading the packed register, and if it survives dead-code removal, main'sunsupported live usecheck throws as before. TheSampleId << 8 | Layer << 16fallback is gone.It also fixes a bug in the old range check:
count <= first + width - offsetunderflowed for an extract starting past a field's end, so an extract at offset 13, count 2 was lowered as sample id at offset 5.New recompiler test
pixel_ancillary:A signed extract is lowered as-is because SampleId stays below 16 and Layer below 8192, so neither builtin has bits above its field. That's my inference, not from documentation.
I'll add
Depends on #295to #375 as you suggested.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-04T09:50:11Z.
A follow-up from testing the stricter lowering in GTA V (PPSA04264): one of its pixel shaders is now refused (
packed pixel ancillary input has an unsupported live use). That skips 3 draw kinds on the way into the game which the old fallback drew. The IR, from replaying the request with the uses listed:So on one side of a select it compares the whole raw register with 1. That depends on bits 0..7 and 12..15 too, not just the sample id and layer. Mesa (
ac_nir_lower_intrinsics_to_args.c) documents only the VRS rates (2..5, which are 0 here because we never enable VRS), the sample id (8..11) and the layer (16..). I don't know of a source for bits 0..1, 6..7, 12..15 or 29..31, so I can't make this use exact.Options as I see them:
SampleId << 8 | Layer << 16with every other bit 0, the old behaviour, recorded as technical debt for the undocumented bits.I lean to keeping this PR as you asked (1). If the undocumented bits ever get pinned down, 2 can become a separate PR. Your call though, or @boykopovar's.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T09:51:46Z.
Thanks, that's exactly it. Only extracts that lie entirely inside bits 8 to 11 or 16 to 28 are lowered, every other use still reaches the
unsupported live usecheck, and the new range check can't underflow. On the signed extracts: the extract only reads bits inside the field, and the field holds the low bits of SampleId or Layer, so it gives the same value as on the packed register whatever the builtin holds above the field. That part doesn't depend on an inference.Merged with current main, together with #375, it builds and passes the full ctest here, including
pixel_ancillary. Ready to merge from my side after a PPSA21564 run on my integration branch.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-05T15:41:08Z.
Rebased onto current
main. The conflict was inState.cppwith #469 (null pixel program):main's export-format read andPixelProgramUnsetcheck stay, and this PR's Z-export format check now sits next to them. Build and ctest are clean apart from the failuresmainhas locally. #375, #423 and #448 are restacked on it.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T20:35:11Z.
Review: CHANGES_REQUESTED
Checked the field ranges against Mesa, the Z formats against the gfx10
SPI_SHADER_Z_FORMATenum, and the MRTZ export layout (Z in R, sample mask in B for 32_ABGR).pixel_ancillaryfails with the non-test changes reverted and passes with them. Two small things before merging:Graphics/src/State.cpp:793:DrawRejectioncallsread(cx, 0x1c4), which throws when the register is missing. That breaks the rule stated at the top of the function ("A register a rule needs that is absent gives no verdict here: DecodeState reports it"). Line 775 already reads it withvalue(cx, 0x1c4, zFormat). Could the export check reuse thatzFormat, guarded by whether it was found?core/libs/prx/libSceAgcDriver/tests/Graphics.cppalready coversDrawRejection/DecodeState. Rows that would pin it: formats 1/2/3/9 withZ_EXPORT_ENABLEaccepted; format 0 withZ_EXPORT_ENABLErejected;MASK_EXPORT_ENABLEaccepted with 9 and rejected with 1; formats 4..8 rejected; 0x1c4 absent gives no rejection inDrawRejection.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T08:09:56Z.
Both done in
048d9982:DrawRejectionreuses thezFormatread withvalue()at the top of the depth checks, so a missing 0x1c4 gives no verdict there any more.tests/Graphics.cpphas aZExportTestswith the rows you listed: formats 1, 2, 3 and 9 withZ_EXPORT_ENABLEaccepted, format 0 rejected,MASK_EXPORT_ENABLEaccepted with 9 and rejected with 1, formats 4 to 8 rejected, and 0x1c4 absent accepted. Without theState.cppchange the last row fails withmissing register in context bank at DWORD 0x1c4.agc_driver_graphicsandpixel_ancillarypass.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T08:18:57Z.
Both points addressed in
048d9982: the precheck no longer throws on a missing 0x1c4, andZExportTestspins the format/enable rows. Checked build + full ctest merged onto current main (387/387), andagc_driver_graphics/pixel_ancillaryfail with the non-test changes reverted. Merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T08:59:24Z.
@adriadam10 I don't know what your AI is doing but it keeps spamming the same comment
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T09:04:33Z.
@MichonGoddijn231849 Sorry about that, you were right. My merge script kept reposting the comment every two minutes while the merge was blocked. I've deleted the duplicates and fixed the script so it only posts once.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T09:06:29Z.
Review: APPROVED
Approving: both requested changes are in
048d9982(details in my comment above). CI is green, merging.Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-07T09:21:34Z.
A note from testing this with PPSA14632 (LEGO Horizon Adventures): its layered pixel shaders still fail with
packed pixel ancillary input has an unsupported live use, although they only take the layer field (v_bfe_u32 v2, v2, 16, 11, inside the{16, 13}range).vBfeU32does not emit immediates. The offset isBitwiseAnd(16, 31)and the count isUMin(BitwiseAnd(11, 31), 32 - offset).ConstantFolder::Foldmakes one pass in program order and reaches the ancillaryGetBuiltinfirst, so whenlowerPackedAncillarylooks at its users, their offset and count are not folded yet and the use is skipped. The unit tests build the extract from constants directly, which is why they pass.Lowering at the extract instead works, because the folder reaches it after its offset and count are folded. That means a
BitFieldUExtract/BitFieldSExtractcase that checks whether its source resolves to thePackedAncillaryGetBuiltinand, inside a range, rewrites its source to the field'sGetBuiltinand its offset relative to the field. Both of that title's shaders then recompile (45997 and 6633 words). I can open it as a follow-up or post the patch here, whichever you prefer.