feat(shader): read hull inputs at a control-point index computed from data #4727
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4727"
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 gjonn on 2026-10-12T19:49:24Z.
What
Tessellation lowering refuses a hull LDS read whose input control-point index is computed from data. Its address is not affine in the invocation and relative patch, so the read fails with "the tessellation ring or LDS address is not affine". PPSA01317's hull programs loop over a per-patch mask and read input control points at an index loaded from memory, so main refuses these draws. Stop line: the lowering accepts such a read when the computed part of the address is a whole number of control points and does not depend on the relative patch index.
AddressEvaluatorgives a hull LDS read (only that access kind) a dynamic term: a value that is not affine but is computed without the relative patch index, and the multiple it is scaled by. Terms of the same value add up, so(t << 1) + toft = index << 3is24 * index. Terms of different values keep the gcd of their multiples. The dynamic term never passes through masks, shifts right, disjoint ORs, selects or phis whose arms differ.inputs * localStridein the relative index. When the read has no invocation term, that also sets the local stride.requireRelativeIndependenceaccepts the relative index reaching such a read only with that stride, which the existing replacement of the index by 0 removes.TessellationPointerclamps a hull input control-point index toinputControlPoints - 1(UMin), on both the fast path and the general path. This differs from the console, where an index past the patch reads LDS of a neighbouring patch. The host has no such memory, and Vulkan leaves an out-of-rangegl_inindex undefined. The index is only known when the program runs, so only the offset can be refused at compile time. The clamp is recorded indocs/dev/debt/shader.md. For reads with a static index, the lowering already proves the index is in range, so the clamp has no effect on them.HullSquaredAddress(addressinv * inv) is now refused as "not a whole number of control points" instead of "not affine". It is still refused, and its expected reason is updated.This overlaps the open tessellation stack #4082 → #4114 → #4163 → #4172 → #4201 → #4222 → #4450. In particular, #4201 edits
requireRelativeIndependence. None of those PRs accepts a data-computed control-point index. This PR is based onmainand will rebase on whichever merges first.Tested
Windows 11, MinGW-w64 GCC, NVIDIA RTX 5090 Laptop (Vulkan), Release,
ANYPS5_NO_SHADER_CACHE=1.agc_driver_tessellationgains two triangle-patch hulls derived from itsHullCode:HullDynamicIndexreads its input control point atmin(inv, 2) << 5(v_min_u32thenv_lshlrev_b32). It must draw likeHullCode(levels 1/0/5, culling, winding).HullHalfSlotIndexscales the same index by 16, half the 32-byte slot. It must be refused as not a whole number of control points.Before (main, with the new tests):
With the refusal check removed, the
HullDynamicIndexdraw fails on main with the same error:After:
Before this change, all four tessellation and control-flow tests passed on main (without the new fixtures).
agc_structurizer,agc_shader_memoryandagc_validate_programalso pass with the change.Not tested: console behaviour, or the full ctest suite.
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 kr4y4 on 2026-10-12T22:11:49Z.
A second-vendor run, to go with the RTX 5090 one.
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 (
tessellationAvailable=1). The head0b7de0e73merged intomain584cc4c57.agc_driver_tessellation, with the newHullDynamicIndexdraw andHullHalfSlotIndexrefusal, passes on both GPUs with--repeat until-fail:3.ctest --timeout 120 --parallel 4): 1018 of 1018 on both GPUs.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T01:51:28Z.
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/execution/Tessellation.cppL331core/libs/prx/libSceAgcDriver/tests/execution/Tessellation.cppL331core/libs/prx/libSceAgcDriver/tests/execution/Tessellation.cppL331core/shader/recompiler/Optimization/src/TessellationLowering.cppL545-546core/libs/prx/libSceAgcDriver/tests/execution/Tessellation.cppL324-326, L331core/shader/recompiler/Optimization/src/TessellationLowering.cppL8, L545-546core/libs/prx/libSceAgcDriver/tests/execution/Tessellation.cppL324-326, L331core/shader/recompiler/Optimization/src/TessellationLowering.cppL8, L496-497, L545-546core/libs/prx/libSceAgcDriver/tests/execution/Tessellation.cppL324-326, L331core/shader/recompiler/Optimization/src/TessellationLowering.cppL8, L496-497, L545-546Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-13T06:41:12Z.
Main regression found:
agc_driver_tessellationsegfaults deterministically on RADV since this PR0b7de0e73("feat(shader): read hull inputs at a control-point index computed from data") — verified by checkpoint testing: its parent passes the test, the commit itself segfaults.libvulkan_radeon.so(backtrace is entirely RADV frames — the generated hull shader's SPIR-V drives the driver to a segfault, rather than our code faulting directly). Deterministic 3/3 on RX 9070 XT / RADV GFX1201, CachyOS, kernel 7.2.9, GCC 16.2.1, Release.main's full suite is red on RADV (1013/1014 with only this failing).Reproduce:
The failure is inside the driver, which usually means the emitted SPIR-V is malformed in a way lavapipe and the Windows drivers tolerate but RADV does not — the hull input indexing this PR adds is the prime suspect. Happy to provide the full backtrace, the generated SPIR-V dump, or bisect further within the commit if useful.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-13T06:58:57Z.
Additional data point on the regression: I checked whether the open #4723 (the hull input component-offset fix, rebased on top of current main including this PR) resolves the segfault — it does not;
agc_driver_tessellationcrashes identically with it applied. That points at the computed-index path this PR added (inPatch(...)on the vertex computation) rather than the constant-offset component indexing.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T08:05:09Z.
Thanks for the bisect. I think this is a Mesa 26.2 bug, not something wrong in the SPIR-V this PR emits:
spirv-val, and every computed index is in range ([3][2] uvec4at Location 0, vertex index clamped to 2).nir_opt_varyings, reached fromradv_graphics_shaders_link_varyings. A release build has no assert and goes on to the segfault you see.So it is best reported to Mesa; the four
.spvstages and a smallvkCreateGraphicsPipelinesharness reproduce it without the emulator, and I can attach them here if you want to file it.