feat(agc): rebuild the hull's relative patch index when it is used as data #4201
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4201"
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 Celegans12 on 2026-10-12T01:12:20Z.
What
Stacked on #4172; please review the last commit only.
Tessellation lowering refuses hull and domain programs whose relative patch index (hull
v1[7:0], domainv7) reaches anything but a ring or LDS address, because one Vulkan patch per hull patch slot has no such index of its own.(PrimitiveID mod PRIM_GRP_SIZE) mod NUM_PATCHES(a domain'sgl_PrimitiveIDis its hull patch's, so both stages compute the same number): hull threadgroups takeNUM_PATCHESpatches out of eachGE_CNTL.PRIM_GRP_SIZEprimitive group.GE_CNTL.BREAK_WAVE_AT_EOI(bit 18) set. With it clear the instances share threadgroups and the index counts on through them, so such programs are still refused. #4450 numbers the patches across instances for that case.PRIM_GRP_SIZE(bits 8:0) andBREAK_WAVE_AT_EOIjoin the tessellation configuration (draw, validation and pipeline keys, the hull and domain cache keys, recompile request version 24). A missing GE_CNTL throws. Local programs still refuse the index: there it is a relative vertex slot whose value depends on how the hardware lays out vertices in a threadgroup.The model is not measured on the console;
debt/shader.mdsays so. PAL says a group size that is not a multiple of the patch count is not allowed, yet PPSA26344's terrain draws run withPRIM_GRP_SIZE64 andNUM_PATCHES63 (GE_CNTL 0x8040, BREAK_WAVE_AT_EOI clear), so on their own they are refused here and need #4450.Tested
Based on
mainf265cd55plus #4172. Windows 11 (MinGW-w64 GCC 15.2.0) and Linux: configure -DBUILD_TESTING=ON, targeted test builds, ctest. Measured on #4222's head, which contains this PR:agc_driver_tessellation,agc_shader_memory,agc_driver_graphics,agc_tessellation_factor_ringandagc_driver_bda_devicepass (5/5)main: the same 5 tests pass (5/5)log_macros, which fails onmaintoo; Linux (upstream's job in WSL) merged withmain5a81f608: 1089/1091,agc_driver_bc_block_copyandagc_driver_depth_compare_copyfail on thatmainas wellagc_driver_tessellationgainsRequireRelativePatches: the hull writesfloat(rel + 1)as a patch constant, checked at NUM_PATCHES/group 3/3, 2/4, 3/4 (patches 6 and 7, which rule out 0,id mod 3andid mod 4) and 3/2 with BREAK_WAVE_AT_EOI set; a missing GE_CNTL and a clear BREAK_WAVE_AT_EOI are refused. A domain pair (DomainRelativeData) runs the same cases.agc_driver_graphicsdecodes GE_CNTL 0x8040 and 0x5fe3f, andagc_shader_memorycovers version 24 and the hull/domain keys. They fail on #4172's head with the old refusal.Not tested: console behaviour.
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 Celegans12 on 2026-10-12T02:09:37Z.
I force-pushed this after a Yōtei run showed the first version was too strict. The terrain draw runs with
PRIM_GRP_SIZE64 andNUM_PATCHES63, even though its hull header says 63/63, so the old "must be a multiple" refusal stopped the game. The index is now(PrimitiveID mod PRIM_GRP_SIZE) mod NUM_PATCHES, which is the same as before whenever the size is a multiple, and only a missing GE_CNTL is refused. The description and the TechnicalDebt line say this now, andRequireRelativePatchesgained 3/4 and 3/2 cases that tell the formulas apart.Checks after the change
mainceb342b9: 924/925 pass;agc_driver_depth_compare_copyalso fails onmain.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-12T03:45:28Z.
One more push here: Yōtei's next terrain domain program (0x8068fbd900) uses the relative patch index as data too, so domain programs now get the same
(PrimitiveID mod PRIM_GRP_SIZE) mod NUM_PATCHES. A domain'sgl_PrimitiveIDis its hull patch's, so both stages agree on the number, andPRIM_GRP_SIZEnow keys the domain cache key as well. Local programs still refuse it, since their index is a vertex slot that depends on how the hardware packs a threadgroup.RequireRelativePatchesgained a domain pair over the same four configurations. Linux (upstream's job, #4222's head on top, merged withmaind146ec1b): 928/929, withagc_driver_depth_compare_copyfailing onmaintoo.Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-12T11:56:43Z.
Data point from Ghost of Yōtei (PPSA26344) on the instancing model here: on that title, the instances of a tessellated draw share hull threadgroups. Restarting the relative patch index with each instance gives the wrong index there.
What the title programs
0x8040: PRIM_GRP_SIZE 64, BREAK_WAVE_AT_EOI (bit 18) = 0.0x1043f: NUM_PATCHES 63, 4 input and 4 output control points.DRAW_INDIRECT. Their GPU-written records hold 4 vertices and 2 to 3,157 instances, so each instance is a single patch.Why the per-instance restart is wrong here
With BREAK_WAVE_AT_EOI clear, a threadgroup runs on into the next instance. Patch k of instance i is then linear patch
i * patchesPerInstance + k, and the relative index is((i * P + k) mod PRIM_GRP_SIZE) mod NUM_PATCHES. Here P = 1, so the hardware gives instance i the index(i mod 64) mod 63. The host's PrimitiveID restarts at 0 with each instance, so(PrimitiveID mod 64) mod 63is 0 for every instance.There is also a timing problem for indirect draws. The hull is compiled when the packet is decoded, before the records are read, so it can't see the record's instance count.
What we have locally
We have this working in #4450, a draft stacked on #4222 (only its top commit is new):
InstanceIndex - BaseInstance) to the hull through one extra interface slot. When an instanced draw's instances share threadgroups,groupedPatchnumbers the patchesinstance * P + PrimitiveIDand then takes the same two remainders.shaderDrawParameters. Without it, an instanced hull that uses its relative index as data is refused.Would you rather fold this into #4201, or keep #4450 as a separate PR on top of #4222? Either works for us. If you fold it in, I'll close #4450.
A smaller point from reading the stack: the hull's patch-constant bound compares
address.constantwith one patch's control points (outputs * controlStride). The domain's PatchInput check usespatchesPerGroup * outputs * controlStride. It makes no difference for Yōtei, but the two bounds probably should agree.(AI-assisted: written with Claude.)
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T12:56:37Z.
Rebase handoff — the chain is complete:
rebase/4114→rebase/4163→rebase/4172→ this, all on currentmain. Authorship unchanged; this link applied cleanly (no conflicts).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 up the whole chain:
Heads:
4114=d0ea5f4d1,4163=652f2763d,4172=65ad9582b,4201=53a35dc8c.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-13T01:44:35Z.
You're right, and thanks for checking it against the title's registers. I had assumed every instance starts its own hull threadgroups, and with GE_CNTL 0x8040 that assumption doesn't hold, so on Yōtei #4201 alone would draw the terrain with every instance at relative patch 0 and never say so.
I'd keep #4450 as its own PR on top of the stack. It's your work and your test, and it carries the in-game result. To make #4201 honest on its own, it now decodes
GE_CNTL.BREAK_WAVE_AT_EOI(bit 18) into the tessellation configuration and refuses a hull or domain that uses its relative index as data when the bit is clear. It only rebuilds the index when every instance is sure to start a new threadgroup. I used your field name,breakAtInstance, and the same draw, validation and pipeline keys. #4201 also puts it in the hull and domain cache keys, since there it decides whether a program compiles at all. The downside is that #4201 alone now refuses Yōtei's terrain draws until #4450 is in. Your PR then replaces that refusal with the instance numbering and can drop its own decode. I can't refuse only the instanced draws in #4201, because draw entries are reused across instance counts, which your PR handles.The whole chain had to be rebased anyway.
mainnow writes request version 19 (#4031 landed this morning), so the stack moved to 20/21/22 andbreakAtInstancesits in #4201's version 22. Your commit then needs no request version of its own. I've rebased it onto the new stack locally to check that the two fit together. The rebase drops your decode and serialization lines, swaps the cache-key bit for yourTessellationInstancePatches, and replaces the refusal with your numbering. I'm happy to push that to a branch on my fork if it saves you the conflicts; it's still your commit and your PR. On that local rebase,agc_driver_tessellation,agc_driver_graphicsandagc_shader_memorypass.agc_shader_memoryneeded one line, because yourinstancedcopy now inheritsbreakAtInstance = truefrom the hull fixture. The terrain hull with 0x8040 recompiles there too (388,903 words).On the smaller point, I agree. #4163 now checks the hull's patch-constant writes against the same bound as the domain's reads: above the control points of all NUM_PATCHES patches, not just one patch's. The descending-record test hull therefore draws at 128 patches per group and is refused at 129. At 129 its lowest record would land inside the last patch's control points. Replayed offline with the title's own GE_CNTL 0x8040, the terrain hull (0x80002fc700) now stops at the new refusal. With the bit set in the request, it passes the tighter bound and recompiles completely (388,903 SPIR-V words).
Details
agc_driver_graphicschecks 0x8040 → 64 primitives, bit clear; 0x5fe3f → 63, bit set.agc_driver_tessellation:HullRelativeDataandDomainRelativeDatawith the bit clear ("GE_CNTL.BREAK_WAVE_AT_EOI is clear, so the instances of a draw can share hull threadgroups").RequireRelativePatchesruns its four configurations with the bit set.agc_shader_memorychecks that the bit survives serialization and changes only the hull and domain cache keys.agc_driver_tessellationfails with "a tessellation program was accepted although GE_CNTL.BREAK_WAVE_AT_EOI is clear". WithbreakAtInstancetaken out of the cache key,agc_shader_memoryfails on the key check.log_macrosfails here on every branch). Linux (upstream's job in WSL), #4222's head merged withmaind1fd9372: 1003/1004 pass;agc_driver_depth_compare_copyalso fails onmain.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-14T01:56:40Z.
Quick note: I restacked this on #4172's new head, which now has the block-condition fix from the review there. While rebasing I noticed
maintook request version 23 for the pixel layer export flag, so this PR's tessellation fields now come in at version 24 (agc_shader_memorychecks the new prefix). Nothing else changed in this commit. The tessellation, shader memory, graphics, factor ring and BDA device tests pass on #4222's head on Windows and on Linux.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-14T03:07:00Z.
Rebased the chain again after #5234 landed. The only overlap was in the tests and the debt list: #5234's integer-partitioning test and this PR's relative-patch test both sit in
Tessellation.cpp, and both debt entries are kept. Nothing in the code changed, and request version 24 is still free onmain. New heads: #4172866ed445b9, this one2eda9f893c, #4222c1e4a0ba8b. On #4222's head the tessellation, shader memory, graphics, factor ring and BDA device tests pass on Windows (NVIDIA) and on Linux merged withmainf265cd55.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T05:28:15Z.
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.cppL1867-1868, L1874