fix(shader): index tessellation attributes at a constant address with constants #8884
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8884"
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 thuanquang on 2026-10-21T04:28:22Z.
What
Fixes #8861.
TessellationPointer(SpirvModuleEmitter.cpp) computes the vertex, location and component indices of a tessellation attribute access from its address withOpUDiv,OpUMod,OpShiftRightLogicalandOpBitwiseAnd. It does this even when the address is an immediate. In the default build nothing folds them, since SPIRV-Tools is off, so the driver gets access chains whose indices are arithmetic on constants.AMD's Windows driver reads a per-vertex tessellation control output indexed that way wrongly. In
agc_driver_tessellation's merged hull program, invocation 0 reads control point 2's level from the per-vertex record that stands in for LDS. That read came back wrong, so a patch was missing or drawn flat, and which one changed from run to run.With an immediate address, the indices are now computed on the host and emitted as
OpConstants, which is the shape glslang emits. Dynamic addresses are unchanged. The host clamps the control point asinPatch()does on the dynamic path: a hull input toinputControlPoints - 1and, sincee4de56f3ce(from review), a domain input tooutputControlPoints - 1.How it was narrowed down on an RX 6700 XT, with local experiments that are not part of this PR:
mainds_read_b32at offset 72) replaced with a copy of its own registermain, so it is not cross-invocation visibilityWorkgroupmemory scope andAcquireRelease | WorkgroupMemory | UniformMemory | ImageMemoryinstead ofInvocationandNoneThe merged hull case also gets a new check: no access-chain index in its hull stage may be integer arithmetic on two constants. That catches this shape on every device, lavapipe included. On
mainthe check fails.Tested
Windows 11 26200, RX 6700 XT (gfx1031), AMD driver 32.0.21045.5002, MinGW GCC 15.2.0 Release,
ANYPS5_REQUIRE_VULKAN=1. Unless a line says otherwise, the runs below are of3f059e58conmainf47c85663;054f8ff4dthen added @MarcZX10's propagation to the new check, ande4de56f3cethe domain-input clamp.agc_driver_tessellation, 3 runs per side from renamed copies of the executable, so the driver's pipeline cache starts empty:mainfails 3 of 3: level-1 patch not drawn once, level-5 patch without interior points twice.--repeat until-fail:3: 10 of 10 pass with this PR. The 10 areagc_driver_tessellation,agc_driver_prepared_graphics,agc_driver_provoking_vertex,agc_driver_rect_list_corner,agc_driver_pixel_barycentric_emulation,agc_driver_graphics,agc_driver_bda_device,agc_shader_memory,agc_tessellation_loweringandagc_shader_disk_cache.ctest -Von the same 10,maind0852defaagainst the same change ond0852defa, then again on this head:mainpasses 9 of 10 (agc_driver_tessellationfails); this PR passes 10 of 10.VUID-lines on either side.VK_LOADER_DEBUG=layershows the layer inserted in every GPU test process.the merged hull program indexes a tessellation attribute with arithmetic on constants instead of a constant.e4de56f3ce), with this head merged intomain6ef5a1c4c9, on AMD driver 32.0.21045.16010 (this PC's driver since 2026-10-21; the runs above used 32.0.21045.5002): a newagc_tessellation_loweringcase emits a domain read at the immediate address3 * 16, with 3 output control points and a 16-byte stride, and checks that the access chain indexes control point 2.failed: a domain read at an immediate address past the last control point reads the last control point.VUID-lines;VK_LOADER_DEBUG=layershows the layer inserted.outputs * controlStride(TessellationLowering.cpp:744-746).Other GPUs, from reviewers:
agc_driver_tessellationpasses 5 of 5 onmain2c4b116da9and on this head, so that driver does not show #8861; the 14 tests matchingtess|hull|spirv|recompiler|geometry|^agc_driver_graphics$pass on this head.maincecb540a6on an NVIDIA RTX 4080 SUPER (616.92, Windows 11 Pro 26200): the 10 tests pass 3 of 3. Withmain'sSpirvModuleEmitter.cppand this PR's tests,agc_driver_tessellationfails 3 of 3 with the new constant-index check's message, and with both files atmainit passes, so that driver does not show #8861's wrong patches either.054f8ff4don an RX 6700 XT with AMD driver 26.10.1 (Windows 11 22621), 10 runs per side:agc_driver_tessellationfails 10 of 10 onmaina6dcea927(the level-1 patch was not drawn as one flat triangle). It passes 10 of 10 with this PR and #9056 merged onto thatmain.054f8ff4dmerged intomaina6dcea927on 32.0.21042.62, the driver where they first saw the failure: an RDNA 2 iGPU (gfx1036), Windows 11, with an empty pipeline cache for each run.agc_driver_tessellationfails 3 of 3 onmainand passes 3 of 3 with this PR. An RTX 5070 Ti (617.42) passes 3 of 3 on both sides. Of 23 related tests on the PR side, onlyagc_driver_sample_order_grid_referencefails on the iGPU, and it fails onmaintoo (#9056).agc_driver_tessellationandagc_tessellation_loweringpass 3 of 3.Not tested:
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:46:56Z.
Review: COMMENTED
The regression can miss the exact old index chain it is intended to reject.
foldedonly records an integer op when both operand IDs are inconstants. With the previous emitter,OpUMod(address, stride)can meet that condition, but the subsequentOpShiftRightLogical(UModResult, 4)and the component shift/and consume result IDs that are not added toconstantsor propagated throughfolded. The access-chain indices can therefore remain unmarked and the test may pass with the old emitter restored. Could the check evaluate/propagate constant-expression results (or inspect the expected access-chain index definitions recursively), and confirm that reverting only the emitter makes this assertion fail?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:52:21Z.
Code review location:
core/libs/prx/libSceAgcDriver/tests/execution/Tessellation.cpp; line 962A small propagation change makes this catch chained expressions too:
Then the
OpShiftRightLogicalandOpBitwiseAndresults derived from the foldedOpUModbecome marked before the access chain is checked.Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-21T05:31:20Z.
@MarcZX10 good catch, thank you. I applied your suggestion: an operand now counts if it is a constant or an already-folded result, so chained shifts and masks are marked too. The new head is
054f8ff4d.On
main's merged hull module (dumped from the same test):OpUDivof two constants). It did fail onmain, but only through those.On the RX 6700 XT:
the merged hull program indexes a tessellation attribute with arithmetic on constants instead of a constant).Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:53:35Z.
Review: APPROVED
The updated regression now propagates folded integer expressions through chained shifts/masks and checks the access-chain indices, addressing the false-negative risk I raised. The author reports the test fails with only the emitter change reverted and passes with the fix on the RX 6700 XT; the targeted AMD before/after runs and validation-layer results are recorded in the PR. I reviewed the updated diff and found no remaining blocker. I could not reproduce the GPU path in this Linux environment.
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-21T06:20:54Z.
A Linux run, since this PR's runtime CI jobs were skipped. It uses lavapipe from Mesa 25.2.8 with LLVM 20.1.2, the same driver as Linux CI, on Ubuntu 24.04 (WSL) with GCC 13.3, Release,
-DANYPS5_ENABLE_SPIRV_TOOLS=ONas on CI,ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1.This PR's commit
054f8ff4dwas applied onto amaind0852defabuild. That tree also carries #8055's float-atomic files, which this test doesn't reach.agc_driver_tessellationpasses 3 of 3, and the new SPIR-V check passes, so lavapipe's merged hull module has no constant-arithmetic indices either.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-21T06:21:37Z.
Independent test on a second AMD driver and an RDNA 2 iGPU, the setup the PR lists as not tested.
Setup: AMD Radeon 680M (RDNA 2 iGPU, Ryzen 7 6800H, deviceID 0x1681), AMD Windows driver 32.0.21030.2001 (Adrenalin 25.10.30.02, Vulkan 1.4.315), Windows 11 26200, WinLibs GCC 15.2.0 r7, Release.
mainis1ff5c8ac5. The branch is this PR's head054f8ff4dmerged into that samemain, built in a separate build directory.ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1on both sides.agc_driver_tessellation, 3 runs per side from renamed copies of the executable (empty driver pipeline cache):mainmerged hull program, unculled: the level-1 patch was not drawn as one flat triangle, centre (16, 24, 40, 255)merged hull program, unculled: the patch with level 0 was not culledRun 3 on
mainhits a third check that #8861 doesn't list, which fits the "different wrong patch on each run" reading.ctest --repeat until-fail:10:mainfails on the first iteration; this PR passes 10 of 10.Khronos validation layer (SDK 1.4.363,
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -V) on the PR's 10 tests (agc_driver_tessellation,agc_driver_prepared_graphics,agc_driver_provoking_vertex,agc_driver_rect_list_corner,agc_driver_pixel_barycentric_emulation,agc_driver_graphics,agc_driver_bda_device,agc_shader_memory,agc_tessellation_lowering,agc_shader_disk_cache):main: 9 of 10 pass;agc_driver_tessellationfails.was not found but was requested by env var VK_INSTANCE_LAYERSon either side.VUID-lines. Both sides have the same single error, fromagc_driver_rect_list_corner:VUID-VkShaderModuleCreateInfo-pCode-08737,Expected vector sizes of Result Type and the condition to be equal: Select(OpSelect %v4floatwith a scalar condition). It is onmainalready and unrelated to this change.Result: the fix holds on a second AMD Windows driver version and on RDNA 2 integrated graphics.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T07:48:09Z.
Thanks for both follow-ups. The RX 6700 XT run with the emitter-only negative control confirms the new constant-index assertion catches the original path, and the Linux/lavapipe run extends coverage to the other CI driver. The independent Radeon 680M comparison is especially useful: three failures on the same
mainbuild versus 10/10 passes on this head, with the validation-layer suite also clean of new VUIDs.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-21T14:54:42Z.
An RDNA 3.5 data point: Radeon 860M (gfx1152, Windows 11 26300), AMD driver 32.0.13058.8001, MinGW GCC 15.2 Release.
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, and each run used a renamed copy of the exe, so the driver's pipeline cache started empty.agc_driver_tessellationmain2c4b116da9054f8ff4deSo this driver and GPU don't show #8861: the merged hull check passes on
main, and the 860M can't serve as a red control. The PR doesn't break it, and the new constant-index assertion passes here.On the PR head, the 14 tests matching
tess|hull|spirv|recompiler|geometry|^agc_driver_graphics$pass. I built with-k 0; the only target that doesn't build isImageArrayWindowPastLayerLimit.cpp, as onmain.Imported from boykopovar/AnyPS5. Originally posted by simnJS on 2026-10-21T16:28:12Z.
NVIDIA, Windows. GeForce RTX 4080 SUPER, driver 616.92 (32.0.16.1692), Windows 11 Pro 26200, Ryzen 9 7950X3D, WinLibs GCC 15.2.0 r7, Release.
Head
054f8ff4dmerged intomaincecb540a6(clean merge).ANYPS5_GPU=NVIDIA ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1,ctest --test-dir build -R "^(agc_driver_tessellation|agc_driver_prepared_graphics|agc_driver_provoking_vertex|agc_driver_rect_list_corner|agc_driver_pixel_barycentric_emulation|agc_driver_graphics|agc_driver_bda_device|agc_shader_memory|agc_tessellation_lowering|agc_shader_disk_cache)$" --output-on-failure --timeout 120 --repeat until-fail:3 -V.Selected GPU name=NVIDIA GeForce RTX 4080 SUPER vendor=0x10de device=0x2702 subgroup=32appears inagc_driver_tessellation,_pixel_barycentric_emulation,_prepared_graphics,_provoking_vertexand_rect_list_corner.agc_driver_graphics,agc_driver_bda_deviceandagc_shader_disk_cacheprint no device line.agc_shader_memoryandagc_tessellation_loweringrun on the CPU. No test skipped.SpirvModuleEmitter.cpp+ PR testsagc_driver_tessellationthe merged hull program indexes a tessellation attribute with arithmetic on constants instead of a constant, which AMD's Windows driver reads wronglyagc_driver_graphicsagc_driver_bda_deviceagc_shader_disk_cacheagc_driver_pixel_barycentric_emulationagc_driver_prepared_graphicsagc_driver_provoking_vertexagc_driver_rect_list_corneragc_shader_memoryagc_tessellation_loweringWith both files at
main, the test file included,agc_driver_tessellationpasses 3 of 3 (0.95, 0.64, 0.61 s). It passes 3 of 3 again with__GL_SHADER_DISK_CACHE=0set; I did not check that the Windows driver honours that variable. All runs used the same executable name, not renamed copies. So this driver does not show #8861's wrong patches, and the PR's new SPIR-V check is the only red result onmainhere.Khronos validation layer not run: the Vulkan SDK is not installed on this machine.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T18:08:55Z.
Review: CHANGES_REQUESTED
Thanks for the fix and the thorough multi-GPU data. One difference from the dynamic path remains:
SpirvModuleEmitter.cpp:850: the dynamic path passes the control point throughinPatch(), which clamps withUMinfor bothControlInput(toinputControlPoints - 1) andEvaluationInput(tooutputControlPoints - 1). The immediate path clamps onlyControlInput, so an immediateEvaluationInputaddress at or beyondstride * outputControlPointsgives an out-of-range access-chain index wheremainclamped. Please clampEvaluationInputtooutputControlPoints - 1on the host as well, and add a case to the test with an immediate address past the last control point.Everything else matches the dynamic path (
LocalOutput/patch, own-lane kinds,% strideoffsets).Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T23:23:05Z.
Validated on AMD's Windows driver: Radeon RX 6700 XT, AMD proprietary driver 26.10.1, Windows 11 10.0.22621, WinLibs GCC 15.2 UCRT, Release.
agc_driver_tessellation, run 10 times one after another:maina6dcea927: fails 10 of 10, each time withmerged hull program, unculled: the level-1 patch was not drawn as one flat triangle.main, together with #9056: passes 10 of 10. #9056 changes only the sample order tests.Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-21T23:46:28Z.
The run on 32.0.21042.62 you asked for. AMD Radeon RDNA 2 iGPU (
1002:13c0, gfx1036), AMD driver 32.0.21042.62, Windows 11, WinLibs GCC 15.2.0, Release,ANYPS5_GPU=AMD ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1.mainisa6dcea927; the PR side ismainwith this head054f8ff4dmerged (clean), built in the same build directory. Each run used a renamed copy of the executable, so the driver's pipeline cache started empty.mainagc_driver_tessellation, AMDmerged hull program, unculled: the level-1 patch was not drawn as one flat triangle, centre (16, 24, 40, 255)agc_driver_tessellation, RTX 5070 Ti (617.42)Your 10 tests plus
agc_tessellation_factor_ringand the sample-order and multisample tests (23 in all,ctest -j1) on the PR side: the 5070 Ti passes them all; on the AMD iGPU onlyagc_driver_sample_order_grid_referencefails, which fails onmaintoo (#9056's thread; not related to this change).Not run: the Khronos validation layer (not installed on this machine).
AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-22T04:03:57Z.
@adriadam10 done in
e4de56f3ce. The immediate path now clamps anEvaluationInputcontrol point tooutputControlPoints - 1, asinPatch()does on the dynamic path.The new case is in
agc_tessellation_lowering(CPU only). It emits a domain read at the immediate address3 * 16, with 3 output control points and a 16-byte stride, and checks that the access chain indexes control point 2. It builds the IR directly because I found no guest program that reaches this: the lowering refuses a domain read whose immediate offset ends pastoutputs * controlStride(TessellationLowering.cpp:744-746).RX 6700 XT, AMD driver 32.0.21045.16010, this head merged into
main6ef5a1c4c9:failed: a domain read at an immediate address past the last control point reads the last control point.VUID-lines.Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-22T04:23:18Z.
Re-ran
e4de56f3con the same AMD driver as before: RDNA 2 iGPU1002:13c0, 32.0.21042.62, Windows 11, WinLibs GCC 15.2.0, Release,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1. The head is merged onto the earlier base, along with #9056, #9057 and #9503.agc_driver_tessellationandagc_tessellation_loweringpass 3/3 on the iGPU (ANYPS5_GPU=AMD), so theEvaluationInputclamp keeps the fix there.AI-assisted: yes (Claude Code); results above were run on this machine.