fix(recompiler): match image-table T# halves offset before and after readfirstlane #8991
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8991"
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 Tamalero on 2026-10-21T08:50:25Z.
What
Marvel's Guardians of the Galaxy (PPSA01748) stops about 4.5 minutes into boot, after the opening menus, on compute shader 0x3b91c3e00 (#7362):
Cause: the key's range is not what blocks this shader, as #7362 assumed. The shader runs a waterfall loop and loads its 8-dword T# from a table behind a 64-bit pointer, in two
s_load_dwordx4halves:The first half's offset is
ReadFirstLane(key, exec) << 5. The second half's offset isReadFirstLane(Select(exec, (key << 5) + 16, old), exec): its +16 is added before the lane read.TryMakeTableColumnsplits immediate addends only at the top of the offset, so the second half got a different base and a zero addend. The column was refused, andGetHandlethrew. The key bound (#7388) and the select condition validation were not involved.Fix: when the existing base comparison fails,
TryMakeTableColumncompares both offsets in one first-lane form: (lane value, mask, shift, addend).v_readfirstlanecommutes with a left shift and an immediate add, and it reads the active arm of a select whose condition the mask implies. The select is peeled withDetail::ActiveMaskImplies, the same rule the SRT walker uses since #7388. Two offsets match only when the lane value, mask and shift are equivalent. The parsed addend replaces the zero one, so the existing checkoffset + addend == first + 4 * dwordstill decides whether the words form one record. The column's key stays dword 0's real offset; nothing else in the plan changes.The column has no key domain, so it binds the snapshot domain (up to 65536 records), as unkeyed pointer tables already do. The assumption about inactive lanes is the one #7388 documented, and I extended that entry in
docs/dev/debt/shader.md: with no active lane the hardware reads lane 0 of the inactive arm, and the table still binds the whole record.Tested
Linux (CachyOS, kernel 7.2.9), GCC 16.2.1, Release,
BUILD_TESTING=ON, RTX 4090 (NVIDIA 615.78.08).verifySplitWaterfallImageTableintests/ShaderMemory.cpp, run byagc_shader_memoryandagc_shader_bindless. A waterfall loop loads one T# as twos_load_dwordx4halves, the second offset formed per lane withv_lshl_add_u32 key, 5, 16. The test checks that the T# is planned as one pointer-table column (stride 32, 8 words, the second half's addend folded) and that record 0's snapshot holds the stored T#. With +32 (the next record) or +8 (a misaligned half) instead of +16, the column must still be refused.ResourceTracker.cpprestored tomain, bothagc_shader_memoryandagc_shader_bindlessfail with the title's message (GetImageResource dword 0 is not a valid runtime value).ctest -R '^agc_shader': 31 of 31 pass.ctest -R '^agc_': 849 of 849 pass (1 skipped,agc_driver_stencil_ref_export).python3 tools/check_conventions.py --base origin/mainandtools/check_test_registration.py: pass.main6830c9164with no other changes:main6830c9164LoadAddressU32@pc=0x4380main+ this changeThe shader is large (1,722,971 SPIR-V words), and its first pipeline build holds the warning screen at about 0.3 FPS for a few minutes on a cold cache. The run then stops later, in the first level, on a separate
AGC graphics: CB metadata pass over part of a color target. That is not part of this change; I'll report it separately.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)Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by clairtonmichel on 2026-10-21T09:05:56Z.
Tested on AMD Ryzen 7 9800X3D and AMD Radeon RX 7900 XTX (Fedora Linux, Mesa 26.2.5):
agc_driver_image_table,cache,reuse, etc.): 100% passed successfully (6/6 tests green in 0.42s).readfirstlaneworks flawlessly on host. Great fix!Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T09:35:59Z.
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/Optimization/src/ResourceTracker.cppL579-582core/shader/recompiler/Optimization/src/ResourceTracker.cppL579-582core/shader/recompiler/Optimization/src/ResourceTracker.cppL579-582Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
docs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/shader/recompiler/Optimization/src/ResourceTracker.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceTracker.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceTracker.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/shader/recompiler/Optimization/src/ResourceTracker.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceTracker.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceTracker.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceTracker.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdImported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-21T19:20:57Z.
AMD result for this PR: Marvel's Guardians of the Galaxy (PPSA01748) on a Radeon Pro V620 (RADV, Mesa 25.2.8, Ubuntu 24.04, kernel 6.8), built from this PR's head 2c77b0f56 with GCC 13.
The refusal this PR fixes is gone on AMD as well: the opening menus render, START GAME goes through, and the MARVEL logo intro plays. There is no
GetImageResource dword 0refusal on 0x3b91c3e00.About 10 minutes after START GAME the process gets SIGSEGV inside
libvulkan_radeon.so. The core puts it inGraphics::Pipeline::Pipeline→LinkPipelineFromLibrariesfor a later draw. WithAPS5_NO_GPL=1it dies at the same instruction in the driver. So I think it's a separate RADV problem, not part of this change:agc_shader_replay --materializeof 0x3b91c3e00's captured dispatch completes on the same machine.agc_compute_pipeline_replay(1 to 9 s each).I haven't narrowed down which RADV function or which pipeline it is yet. I'll open a separate issue once I have that.
Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T19:55:26Z.
Checked the diff:
ParseFirstLaneOffsetonly matches two offsets when lane value, mask and shift are equivalent, the select is peeled with the sameActiveMaskImpliesrule as #7388, and the existingoffset + addend == first + 4 * dwordcheck still decides the record. The new test pins the +16 column and keeps +32/+8 refused, and it fails onmain(the plan throws). Debt entry updated.Added on top: removed the three code comments from
verifySplitWaterfallImageTable(no comments in code). Rebased onto currentmain; merged.