fix(agc): bound tessellation patch records by the draw's patch count #4114
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4114"
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-11T23:32:53Z.
What
Tessellation lowering proves that every ring and LDS address is affine in the control point and the relative patch, with the relative patch bounded by a fixed 256. A hull that lays its patch records out downwards from a base, such as
0x8000 - 208 * (rel + 1), then fails as "not affine", because record 255 would be negative even though the draw never has that many patches.DecodeShaderStagesreadsVGT_LS_HS_CONFIG.NUM_PATCHES(bits 7:0, the patches per hull threadgroup) into the tessellation configuration aspatchesPerGroup, and refuses 0.SharpEmu decodes the field the same way (
PatchesPerGroup = configuration & 0xFF, 0 rejected). PPSA26344's first terrain hull (VGT_LS_HS_CONFIG0x1043f, 63 patches) stores its patch constants at exactly that descending stride and stopped there after #4082.#4451 also adds a request version; whichever lands second renumbers.
Tested
Based on
mainc63dd444. Windows 11 (MinGW-w64 GCC 15.2.0) and Linux: configure -DBUILD_TESTING=ON, full build, --target libs, ctest. Measured on #4222's head, which contains this PR:log_macrosfails on every branch and onmain;patched_librariescannot loadmain'slibkernel_sys.prx); merged withmain14036cb0,agc_driver_tessellation,agc_driver_graphics,agc_shader_memory,agc_driver_bda_deviceandagc_tessellation_factor_ringpass (5/5)main14036cb0: 1047/1049 pass;agc_driver_depth_compare_copyandguest_mathalso fail onmainagc_driver_tessellationgains a hull storing patch constants at0x8000 - 208 * (rel + 1): refused at 256 and 158 patches, rendered correctly at 157 (the boundary).agc_driver_graphicsdecodes 63 and 85 patches and refuses 0;agc_shader_memorycovers version 22 and the hull/domain-only key. Each fails without it.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 tibzejoker on 2026-10-12T00:41:52Z.
GTA V (PPSA04264) data point for this PR and #4082. Windows 11, RTX 4090, MinGW GCC 15.2.
GTA's hull stores its patch constants downward from 0x8000 (the
0x8000 - 208 * (rel + 1)shape you describe), withVGT_LS_HS_CONFIG0xc338 and a maximum tessellation level of 15. Onmain325e0a8bdplus the other PRs GTA needs, this PR and #4082 replace the local patches I had for the same two things, and the hull program now compiles.The next stop is the domain program, which reads those constants:
I opened #4175 for that, stacked on this PR (its last commit only). With it, GTA's Story mode runs past that draw.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T12:30:19Z.
Rebase handoff — this branch was ~362 commits behind
main(labeled needs-rebase for staleness; the rebase itself applied cleanly, no conflicts). Rebased onto currentmain, both commits' authorship unchanged.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
d0ea5f4d1. Since #4163, #4172 and #4201 stack on this branch, I can rebase the chain on top of this if useful — say the word.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T17:15:34Z.
Independent verification of your rebase — the new head builds and passes the full local suite on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): 905/905, conventions green. From my side this is merge-ready.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-13T01:44:32Z.
Thanks for the rebase handoffs across the chain, blawesom. I used your
rebase/*heads to check my own rebase. They also give the stack a RADV/AMD data point that I can't get here. Main has moved a lot since then, so I rebased all six again ontomain510a2188and force-pushed them. Two things onmainchanged the result. First,docs/dev/TechnicalDebt.mdwas split intodocs/dev/debt/, so the chain's entries now live indebt/shader.md. Second, three new request versions landed:mainwrites 19 now.That second point is easy to miss. Your heads kept the chain's request versions at 17/18/19, but
mainhad already written 17 with a different layout, and git can't flag that because the lines look the same. The chain now uses 20 (#4082), 21 (this PR) and 22 (#4201).About listing every link under "Depends on" on #4222: each PR names only its direct parent, and the stack order follows from that.
tools/pr_overlap.pyalso treats every number on that line as a dependency. So I've left it as one number per PR.Details
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 fdfawef324 on 2026-10-13T06:53:41Z.
Evidence from another title, and a bound that may help this PR.
GTA V (PPSA04264, #1203) hits exactly this refusal: a hull shader with 3 control points stores its patch constants downward from the top of a 32 KiB off-chip area, at 0x8000 minus 0x150 × (relative patch + 1). That form is affine; it is refused only by the range check, because
PatchIndexCountassumes relative patch ids up to 255 and 0x7eb0 − 0x150 × 255 is negative.The hardware bound is smaller than 256 regardless of
VGT_LS_HS_CONFIG.NUM_PATCHES: Mesa computes the patches per threadgroup as 256 / max(input, output control points), because the in and out vertices per threadgroup "are at most 256, which is the hw limit" (ac_shader_util.c L948-L954 at 5c142e46). Using min(NUM_PATCHES, 256 / max(in, out)) as the bound would also cover requests saved before the new field, which otherwise read as 256 patches and still fail on this shader.I have a small branch that applies only that hardware bound, without touching the request format or the keys, with a hull test using 336-byte records from 0x8000 and an IR test that checks the lowered offsets for several patches: fdfawef324:fix/recompiler-hull-patch-range. I am not opening it as a separate PR since this one covers the same refusal; feel free to take anything from it, or tell me if you would rather I open it so the two bounds can be combined.
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T09:20:51Z.
GTA V (PPSA04264) with this PR and #4163. Windows Server 2025, RTX 3060, MinGW-w64 GCC 15.2.0.
Base. An integration branch on
main7e181fccthat already has #4082 rebased (7e3eefae) and other open PRs. I cherry-picked 6b15b72e (this PR) and then f4aa18dc (#4163). The branch also carries the hull bound of 256 / max(input, output control points) from my earlier comment. In the merge it applies only whenpatchesPerGroupis unknown (256, i.e. requests older than version 21), so in game the bound isVGT_LS_HS_CONFIG.NUM_PATCHES.Conflicts. Against current
main(fc1f063f) this head conflicts in one file:core/libs/prx/libSceAgcDriver/tests/execution/Tessellation.cpp, in the list inmain(), where #4727 addedHullHalfSlotIndexandRequirePatches(..., HullDynamicIndex, ...). #4082 hits the same place. Everything else merges cleanly.mainstill writes request version 19, so 20 and 21 are free.Tests.
agc_driver_tessellation,agc_driver_graphics,agc_shader_memoryandagc_tessellation_factor_ringpass.check_conventions.pypasses on the two commits.GTA V. The tessellated draw has
VGT_LS_HS_CONFIG0xc338: 3 input and 3 output control points, NUM_PATCHES 56. Hull 0x25cb4ea00 writes 336-byte patch-constant records at0x8000 - 0x150 * (rel + 1), so record 255 would be negative.The next stop is outside this PR.
sceAgcCreateInterpolantMapping, where the driver prepares each program synchronously inResolveShaderAbi: about 4,100 from the disk cache and 3,300 new compiles.GetImageResource dword 0 is not a valid runtime value. That is the same refusal that six programs already log at registration without aborting.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T11:15:41Z.
Checked: the request version is written as 21 and read up to 21 (older requests read 256), the new field is in the draw, validation and pipeline keys and in the hull/domain cache keys only.
agc_driver_graphics,agc_shader_memoryandagc_tessellation_factor_ringpass, andagc_driver_tessellationpasses on CI's lavapipe. The new tests do not build without the change. GTA V runs by @fdfawef324 and @tibzejoker confirm the hull and domain now compile. Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-13T12:17:15Z.
@adriadam10 I rebased the tessellation chain onto current main, and one thing in this PR had to change: #3763 moved main's recompile requests to version 21 without adding a field, and this PR also used 21 for the new
patchesPerGroupword. Git merged the two identical lines silently, so a request written by main at version 21 would have been read here with apatchesPerGroupit never had.This PR now writes version 22 and reads
patchesPerGrouponly from 22 on; theagc_shader_memoryexpectations moved with it. Nothing else changed, the rest of the diff is line-for-line the one you looked at. #4201 moves from 22 to 23 the same way, and #4163, #4172 and #4222 are plain rebases.Details
version >= 22uforpatchesPerGroup,WriteU32(22u),version > 22u; test prefixNVNQQRYAAAA=(22), unsupportedNVNQQRcAAAA=(23)version >= 23uforprimitiveGroupSize/breakAtInstance, writes 2314036cb0: Linux (WSL, llvmpipe) 1047/1049, the two failures (agc_driver_depth_compare_copy,guest_math) also fail on main; Windows NVIDIA tessellation, graphics, shader memory, BDA device and factor ring tests 5/5Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T12:20:14Z.
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/shader/recompiler/ControlFlow/src/RequestSerializer.cppL751, L783Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T13:31:20Z.
Checked the
NUM_PATCHESdecode (bits 7:0 ofVGT_LS_HS_CONFIG, 0 refused), the bound in hull/domain lowering (Local keeps its own), the draw/validation/pipeline keys and the hull/domain-only cache key, and the version 22 request (older requests read 256).agc_driver_graphics,agc_shader_memoryandagc_tessellation_factor_ringpass;agc_driver_tessellationpasses on CI's lavapipe, with the descending-records hull refused at 158 and 256 patches and rendered at 157. The new tests do not build without the change. Confirmed on GTA V by @tibzejoker and @fdfawef324. Merging once the full Build is green.