Skip to content

fix(recompiler): match image-table T# halves offset before and after readfirstlane - #8991

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
Tamalero:fix/shader-image-table-split-tsharp-halves
Oct 21, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
Tamalero:fix/shader-image-table-split-tsharp-halves

Conversation

@Tamalero

@Tamalero Tamalero commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What

Marvel's Guardians of the Galaxy (PPSA01748) stops about 4.5 minutes into boot, after the opening menus, on compute shader 0x3b91c3e00 (#7362):

GetImageResource dword 0 is not a valid runtime value; chain: LoadAddressU32@pc=0x00004380(GetAddressResource(ReadConst(GetSrtResource, Immediate), ReadConst(GetSrtResource, Immediate)), ShiftLeftLogical32(ReadFirstLane(SelectU32(...)), Immediate), ...)

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_dwordx4 halves:

v_lshl_add_u32     v5, v32, 5, 16
v_readfirstlane_b32 vcc_lo, v32
v_readfirstlane_b32 vcc_hi, v5
s_lshl_b32         vcc_lo, vcc_lo, 5
s_load_dwordx4     s[28:31], s[56:57], vcc_lo   // record = rfl(key) << 5
s_load_dwordx4     s[32:35], s[56:57], vcc_hi   // same record + 16, offset formed per lane
image_sample       v38, v8, s[28:35], s[8:11]

The first half's offset is ReadFirstLane(key, exec) << 5. The second half's offset is ReadFirstLane(Select(exec, (key << 5) + 16, old), exec): its +16 is added before the lane read. TryMakeTableColumn splits 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, and GetHandle threw. The key bound (#7388) and the select condition validation were not involved.

Fix: when the existing base comparison fails, TryMakeTableColumn compares both offsets in one first-lane form: (lane value, mask, shift, addend). v_readfirstlane commutes 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 with Detail::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 check offset + addend == first + 4 * dword still 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).

  • New verifySplitWaterfallImageTable in tests/ShaderMemory.cpp, run by agc_shader_memory and agc_shader_bindless. A waterfall loop loads one T# as two s_load_dwordx4 halves, the second offset formed per lane with v_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.
  • Negative check: with ResourceTracker.cpp restored to main, both agc_shader_memory and agc_shader_bindless fail 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/main and tools/check_test_registration.py: pass.
  • PPSA01748 (content 01.006.000), same route (language, brightness, adjustments → Start Game). Both builds are on main 6830c91 with no other changes:
Build Result
main 6830c91 stops about 4.5 min in, compute 0x3b91c3e00, LoadAddressU32@pc=0x4380
main + this change 0x3b91c3e00 dispatches; the photosensitivity warning, the autosave notice and the title screen and main menu render. New Game then loads into the first level.

The 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

Tested and written by Claude (AI assistant) on a contributor's machine.

image image image

@github-actions github-actions Bot added unblocks title Names a title ID on the Unblocks line fix error Closes an issue (Fixes #N) labels Oct 21, 2026
@clairtonmichel

Copy link
Copy Markdown

Tested on AMD Ryzen 7 9800X3D and AMD Radeon RX 7900 XTX (Fedora Linux, Mesa 26.2.5):

  • Built cleanly with zero errors.
  • Ran the image table and recompiler-related test suite (agc_driver_image_table, cache, reuse, etc.): 100% passed successfully (6/6 tests green in 0.42s).
  • Image-table T# halves offset matching before and after readfirstlane works flawlessly on host. Great fix!

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 7223 core/shader/recompiler/Optimization/src/ResourceTracker.cpp L579-582
PR 7395 core/shader/recompiler/Optimization/src/ResourceTracker.cpp L579-582
PR 8939 core/shader/recompiler/Optimization/src/ResourceTracker.cpp L579-582

Some 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.

Pull request Shared files not compared
PR 5021 docs/dev/debt/shader.md
PR 5371 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
docs/dev/debt/shader.md
PR 6235 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
docs/dev/debt/shader.md
PR 6280 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
docs/dev/debt/shader.md
PR 6290 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6412 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
docs/dev/debt/shader.md
PR 6488 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceTracker.cpp
docs/dev/debt/shader.md
PR 6645 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6879 docs/dev/debt/shader.md
PR 6924 docs/dev/debt/shader.md
PR 6947 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 7085 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
docs/dev/debt/shader.md
PR 7484 docs/dev/debt/shader.md
PR 7550 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 7642 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 7684 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceTracker.cpp
docs/dev/debt/shader.md
PR 7922 docs/dev/debt/shader.md
PR 8004 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
docs/dev/debt/shader.md
PR 8077 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceTracker.cpp
docs/dev/debt/shader.md
PR 8625 docs/dev/debt/shader.md

@github-actions github-actions Bot added shader core/shader docs agc libSceAgc* labels Oct 21, 2026
@adriadam10 adriadam10 self-assigned this Oct 21, 2026
Tamalero and others added 2 commits October 21, 2026 20:21
…readfirstlane

A T# loaded as two s_load_dwordx4 halves from a pointer table, where the
second half's offset is formed per lane (v_lshl_add_u32 key, 5, 16) before
v_readfirstlane and the first half's after it (readfirstlane(key) << 5),
was refused: the second half's +16 sat inside ReadFirstLane(Select(exec,
..., old), exec), so TryMakeTableColumn saw a different base and a zero
addend. Compare such offsets in a first-lane normal form (lane value, mask,
shift, addend), peeling selects the mask implies as the SRT walker already
does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… test

Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10
adriadam10 force-pushed the fix/shader-image-table-split-tsharp-halves branch from 2c77b0f to 78178e9 Compare October 21, 2026 18:43
@Tamalero

Copy link
Copy Markdown
Contributor Author

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 2c77b0f 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 0 refusal on 0x3b91c3e00.

  • About 10 minutes after START GAME the process gets SIGSEGV inside libvulkan_radeon.so. The core puts it in Graphics::Pipeline::Pipeline → LinkPipelineFromLibraries for a later draw. With APS5_NO_GPL=1 it dies at the same instruction in the driver. So I think it's a separate RADV problem, not part of this change:

    • Offline, agc_shader_replay --materialize of 0x3b91c3e00's captured dispatch completes on the same machine.
    • All nine compute pipelines over 150k SPIR-V words that the run created replay without error through 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.

@adriadam10
adriadam10 merged commit 415fd71 into boykopovar:main Oct 21, 2026
10 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the diff: ParseFirstLaneOffset only matches two offsets when lane value, mask and shift are equivalent, the select is peeled with the same ActiveMaskImplies rule as #7388, and the existing offset + addend == first + 4 * dword check still decides the record. The new test pins the +16 column and keeps +32/+8 refused, and it fails on main (the plan throws). Debt entry updated.

Added on top: removed the three code comments from verifySplitWaterfallImageTable (no comments in code). Rebased onto current main; merged.

oneandonlydean pushed a commit that referenced this pull request Nov 21, 2026
Brings #8991 (match image-table T# halves offset before and after
readfirstlane).

ResourceTracker.cpp: main's FirstLaneOffset, ParseFirstLaneOffset and
SameFirstLaneOffset go before TryMakeTableColumn, which keeps this
branch's signature with the buffer parameter. Main's first-lane base
check in the column loop merged on its own.
oneandonlydean pushed a commit that referenced this pull request Nov 26, 2026
…ane-masks

Brings #7395's merge of main bd4d801, with #8991. It merged without conflicts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs fix error Closes an issue (Fixes #N) shader core/shader unblocks title Names a title ID on the Unblocks line

Projects

None yet

3 participants