feat(agc): implement quad tessellation with counter-clockwise output and level clamps #4082
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4082"
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-11T22:54:10Z.
What
The tessellation reference path from #1491 accepts only triangle patches with clockwise output, and refuses any HOS level clamp narrower than [1, 63]. Draws with quad patches,
TRI_CCWoutput or a lowerVGT_HOS_MAX_TESS_LEVELabort inDecodeShaderStages.TRI_CCWnow decode, and the domain program getsQuadsandVertexOrderCcw. Isolines, other partitionings, point or line output and the reserved domain still throw.VGT_HOS_MIN/MAX_TESS_LEVELare runtime values: each draw pushes them in the last 8 bytes of the pre-rasterization push constant slot (as the mesh draw words), and the hull reads them there to clamp its factors. One hull serves every level; the levels are in no shader, draw, validation or pipeline key and not in the recompile request. Outer factors that are zero, negative or NaN still cull. Clamps outside 0 <= min <= 63, max >= 1, min <= max throw.TessLevelOuter[0..3]andTessLevelInner[0..1]. The source is the TF ring store in Mesa'sac_nir_lower_tess_io_to_mem.c, the fork the technical debt already cites. Quad hulls using the 16-byte triangle stride are refused.ShaderValidationderives the expected execution modes from the configuration.PPSA26344's first terrain draw uses
VGT_LS_HS_CONFIG0x1043f andVGT_TF_PARAM0x4006a (quad, fractional-odd,TRI_CCW) with a maximum level of 9, as Pipodi decoded on discussion #675.debt/shader.mdnotes that the quad factor layout and the clamp/cull order are unmeasured on the console.Tested
Based on
main4bb2c7f3. 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 here on every branch and onmain, andpatched_librariescannot loadmain'slibkernel_sys.prx(error 127), which this chain does not touchmain8299b2f7: 1033/1034 pass;agc_driver_depth_compare_copyalso fails onmainagc_driver_tessellationgains a counter-clockwise winding case, a clamp case that draws with one compiled hull at max 1 (a level-5 patch goes flat), again at max 64 (it is tessellated again) and at min 5 (a level-1 patch is tessellated; level 0 still culls), a hand-assembled quad patch with opposite CW/CCW winding, and a refusal of a quad hull at the triangle stride.agc_driver_graphicsnow expects the title's registers to decode. Each fails on main; the shared-hull draws also fail with the levels compiled into the hull.Not tested: console behaviour (factor edge order, clamp order).
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 oneandonlydean on 2026-10-13T00:33:08Z.
Needs a rebase: it conflicts with main in
RequestSerializer.cpp(the request is at version 18 now),tests/ShaderMemory.cppanddocs/dev/TechnicalDebt.md, which was split intodocs/dev/debt/.One change while you are there.
VGT_HOS_MIN/MAX_TESS_LEVELare per-draw register values, and this bakes them into the hull as constants and adds them to its cache key (CacheKey.hpp,EmitSetTessellationAttributeinSpirvModuleEmitter.cpp), so a title that changes the maximum level compiles one hull per value. Please pass the two levels to the hull as runtime values and keep them out of the shader cache key and the request, the same as the depth export clamp; the request version then doesn't need to move. The quad domain,TRI_CCWand the factor layout are fine as they are.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-13T01:51:54Z.
@oneandonlydean rebase complete
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T02:19:24Z.
The rebase is clean. The second point is still open:
VGT_HOS_MIN/MAX_TESS_LEVELare still constants in the hull (SpirvModuleEmitter.cpp:1229-1237) and part of its cache key (CacheKey.hpp:110-111), the draw, validation and pipeline keys (DrawLookup.cpp:30,DrawRegisterKey.cpp:87,Draw.cpp:710-711,Pipeline.cpp:828-829) and the request, which went to version 20 for them (RequestSerializer.cpp:522-535). Please pass the two levels to the hull as runtime values and take them out of those keys and the request, so it stays at version 19; or say what stops that here.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-13T02:38:47Z.
You're right, and sorry for missing that part on the first pass. I'll pass both levels to the hull at runtime the way the depth export clamp is passed, and take them out of the cache, draw, validation and pipeline keys and out of the request, so #4082 no longer moves the request version. The rest of the chain then shifts down by one version. I'll restack it and post here when the new head is up.
Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-13T06:15:40Z.
An Intel run, a second hardware driver for the tessellation test.
Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head e1b7688b8 merged into
main495bf91a0, which passes 1023 of 1023 on both GPUs.agc_driver_tessellation,agc_driver_graphicsand theagc_shader_memoryentries (9 entries) pass on both GPUs with--repeat until-fail:3. None of them skipped on the Intel iGPU.ctest --timeout 120 --parallel 4): 1023 of 1023 on both GPUs.No negative control: all three test executables use this branch's new interfaces and don't build against
main's sources.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T06:22:22Z.
Rebased e1b7688b onto
main88107b7das 7e3eefae (author kept: Celegans12). Branch:integ/pr4082-rebasedon the fork.Conflicts:
tests/execution/Tessellation.cpp,main(): #4727 (0b7de0e7) addedRequirePatches(..., HullDynamicIndex, ...)where this PR addsRequireCounterClockwise,RequireLevelClampsandRequireQuads. Kept all four,HullDynamicIndexfirst.TessellationLowering.cppandSpirvModuleEmitter.cppmerged next to #4727's dynamic hull-input index changes, anddocs/dev/debt/shader.mdkeeps #4727's entry plus this PR's two.git range-diffagainst the original commit shows only those context lines.mainis still at request version 19, so the bump to 20 still applies.tools/check_conventions.py --base upstream/mainpasses.Tests (Windows Server 2025, MinGW-w64 GCC 15.2.0):
tests/ShaderMemory.cpp,CacheKey.hpp) passg++ -std=c++23 -fsyntax-only.agc_shader_memory,agc_driver_graphics,agc_driver_tessellation,agc_tessellation_factor_ring. The build directory for this rebase did not configure (its submodule checkout was broken), so nothing was built or linked.The second review point (pass
VGT_HOS_MIN/MAX_TESS_LEVELto the hull at runtime, take them out of the cache, draw, validation and pipeline keys and the request) is still open. This rebase does not change it.GTA V (PPSA04264) stops on this exact check: after 205 frames (17.5 FPS) it aborts with
AGC graphics: tessellation level clamps inside the fractional-odd range [1, 63] are unsupportedfromDecodeShaderStages(State.cpp:619). That run used an integration build onmain7e181fcc.State.cppis the same on88107b7d. The log does not printVGT_HOS_MIN/MAX_TESS_LEVEL(context 0x287/0x286). Because of the order of the checks onmain, the draw must be a triangle domain with fractional-odd partitioning and clockwise output, and both levels must be finite. Beyond that, min > 1 or max < 63. Whether the values are inside what this PR accepts (0 <= min <= 63, max >= 1, min <= max) cannot be read from that log.With this rebase in an integration build (
main7e181fccplus other open PRs, libraries built with GCC 15.2 -O3), GTA V gets past the level-clamp check: the error above no longer appears. It now stops at the next tessellation limitation, in a hull shader:ShaderRecompiler::Recompile: tessellation lowering: the tessellation ring or LDS address is not affine in the control point and relative patch(pc 0xc7c). So this PR removes GTA V's first tessellation stop; the next one is in the lowering, not in this PR's scope.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-13T09:42:59Z.
@oneandonlydean the levels are runtime values now; the new head is
23342340cc.Each draw reads
VGT_HOS_MIN/MAX_TESS_LEVELand pushes them into the last 8 bytes of the pre-rasterization push constant slot, and the hull loads them from there before it clamps its factors. They're out of the hull cache key, the draw, validation and pipeline keys and the request, so #4082 no longer touchesRequestSerializer. One thing I couldn't place: I didn't find a depth export clamp onmainthat reads its value at run time, so I followed the mesh draw words, which reach the mesh shader the same way. If you meant a different mechanism, point me at it and I'll switch.The clamp test now compiles the hull once and draws with it three times: max level 1 flattens the level-5 patch, the next draw at 64 tessellates it again, and min 5 tessellates the level-1 patch. Ported to the old head, where the levels were compiled into the hull, the first of those draws fails.
The rest of the chain is restacked on
main4bb2c7f3.mainitself now writes request version 20 (#423), so #4114 takes 21 and #4201 takes 22, the same numbers they had before.Details
TessellationLevelPushOffsetBytes120, 8 bytes (min and max as f32). Tessellation draws cap every stage's push data in that slot at 120 bytes (DrawCaptureand bothShaderRegistrypaths), andpushDrawConstantsrefuses a stage whose push range would overlap the levels. The hull always declares the push block, soPushConstantStagesincludes the tessellation control stage, as it does the mesh stage.DecodeShaderStagesstill refuses clamps outside 0 <= min <= 63, max >= 1, min <= max.TessellationConfigurationtoGraphics::ShaderStages(minTessellationLevel,maxTessellationLevel).VGT_HOS_*stay inDrawKeyRegisters, which already listed them onmainbecause the decoder reads them.agc_driver_tessellation,agc_shader_memory,agc_driver_graphics,agc_tessellation_factor_ring,agc_driver_bda_device,agc_driver_prepared_graphics,agc_driver_mesh) pass on each of the six heads (RTX 3080 Laptop).log_macros, pluspatched_libraries, which can't loadmain'slibkernel_sys.prx; the chain doesn't touch it); Linux on llvmpipe merged withmain8299b2f7, 1033/1034 (agc_driver_depth_compare_copy, also failing onmain).