fix(shader): resolve table column pointers through Phi nodes #7880
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7880"
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 klosixgaming-arch on 2026-10-19T12:10:05Z.
What
When an indirect table column descriptor pointer has its dword components resolved through a Phi node (e.g. when control flow merges equivalent scalar reads or invariant values),
TryMakeIndirectColumn()fails to match the scalar memory read becausepointer->Argument(dword)->Resolve()remains a Phi node.Traverse through Phi operands in
UnwrapTableRead()to resolve the scalar memory read, verifying that all non-Phi branches converge on an equivalent descriptor read. Any non-Phi leaf that is not a matching table read makes the function returnnullptr.Tested
ctest -R ^agc_shader_memory$(agc_shader_memory_teststarget): passed locally on Windows (x86_64 mingw-w64). CI build jobs (Windows, Linux, relinker) were skipped; only the conventions, labels and eligibility jobs ran in CI.verifyPointerImageTable()andverifyPointerChainImageTable().verifyPointerChainImageTable(): a Phi with different table offsets and a Phi with a non-table branch, both verified usingexpectFailureonGetResourcePlan()expecting"GetImageResource dword 0 is not a valid runtime value".mainwithout the fix, the positive tests fail."pointer chain image table: a phi with a non-table branch was planned as a table".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 savvaniss on 2026-10-19T14:12:33Z.
AMD and Intel Windows data: the 15 tests built from
tests/ShaderMemory.cpppass on an AMD RX 9070 XT and an Intel UHD 770, with and without the change.Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. This head72e97735emerged intomain85029a00f. "Without" means only this PR's diff totests/ShaderMemory.cpp, applied tomain85029a00f.tests/ShaderMemory.cppSo the test changes also pass on
mainwithout the fix. On these GPUs they show no regression, but they don't reproduce the case the fix resolves.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T15:44:30Z.
First AMD-on-Linux (RADV) run of this PR. Merged onto
main43a2abaf7(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8): 1636/1638 with this PR, against 1636/1638 onmain. The failures are the same two on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784). The PR adds no new ctest entry; every existing test it touches passed.GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T21:37:40Z.
@klosixgaming-arch two things before this can go in:
mainwithout the fix as well. Could you add a case that fails onmain(the refusal this PR targets) and passes with it?UnwrapTableReadreturns the read from one phi arm, andTryMakeIndirectColumnkeeps that read's operands:bufferHandle = read->Argument(0)andplan.offset = read->Argument(1). The materializer then usesplan.offsetat the image read (column.selected ? Constant(addend) : plan.offset). If an arm computes its offset or buffer handle inside the arm, those values don't dominate the read after the merge, and the module is invalid even thoughEquivalentValuematches them. Could you require them to dominate the image use (and returnnullptrotherwise), or rematerialize them there, and add a case where the offset is computed in each arm?Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-21T17:24:34Z.
@oneandonlydean pushed
64675a375(one commit on top of2e5004d2a) for both points.1. A case that fails on
main. The two positive cases already in this PR are those cases, and I could reproduce that they fail without the fix. I builtmain(cecb540a6) with only this PR'stests/ShaderMemory.cppdiff applied and ranagc_shader_memory(Windows 11, WinLibs GCC 15.2.0, Release, RTX 5090):Failed, withGetImageResource dword 0 is not a valid runtime value; chain: LoadAddressU32@pc=0x00000060(GetAddressResource(LoadAddressU32@pc=0x00000058(GetAddressResource(Phi(ReadConstBuffer@pc=0x00000044(...That is the refusal this PR targets. I can't explain why savvaniss's run passed without the fix; his table has all 15 tests built from
tests/ShaderMemory.cpppassing onmainwith and without the change, and I only ran the one ctest entryagc_shader_memory, which is where the failure is.2. Dominance. You are right. Taking
plan.offsetfrom one arm is wrong when the arm computes it, because it is substituted into the image handle after the merge.TryMakeIndirectColumnnow returnsfalseunless the offset is an immediate, has no parent block, or its parent block dominates the handle's block (BlockDominateswalks predecessors back to a root block and reports no dominance if it can get there without passing the dominator). I did not add the same check forbufferHandle: it is only passed toMakeRuntimeSource, which builds aDescriptorSourcefrom the handle's constant description and does not keep the IR value, andUnwrapTableReadalready requires the arms'Argument(0)to beEquivalentValue. In the existing positive cases each arm has its ownGetBufferResource, so requiring it to dominate would refuse them (I tried that first andagc_shader_memoryfailed).New case in
verifyPointerChainImageTable: each arm computes the offset (s_lshl_b32 s18, s17, 4) before its own load. Results ofagc_shader_memory:pointer chain image table: a phi whose arms compute their own table offset was planned as a table64675a375: Passed (0.52 s)python tools/check_conventions.py --base origin/mainpasses. I did not run the validation layer on this one (it is a planning change with no Vulkan calls) and did not run the other test targets.AI-assisted: yes. Written with AI assistance and reviewed by me.