Skip to content

fix(recompiler): fold chained immediate addends of image-table record offsets - #7325

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Cleverdee:fix/image-table-nested-addend
Oct 18, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Cleverdee:fix/image-table-nested-addend

Conversation

@Cleverdee

Copy link
Copy Markdown
Contributor

What

SplitImmediateAddend (ResourceTracker.cpp) peels one immediate operand off a T# dword's scalar offset, so a table record
whose two s_load_dwordx4 use chained offsets is not recognized as a table. Demon's Souls (PPSA01342) loads each
32-byte T# like this:

  • dwords 0-3 at soffset X = (key << 5) + C
  • dwords 4-7 at soffset Y = X + 16 (the add is applied to X, not to key << 5)

For dwords 4-7 the old code peeled only the +16 and kept IAdd32(Shl, C) as the base, which never matched the base of
dword 0 (Shl), so TryMakeTableColumn gave up and the shader failed with
GetImageResource dword 0 is not a valid runtime value.

SplitImmediateAddend now keeps peeling immediate IAdd32 operands and sums them modulo 2^32, as the scalar adds do. The
single-add case is unchanged. Chained adds then reach the existing folded-addend path (foldedAddend / foldedCarry),
the same one used by pointer tables whose two loads add different immediates to one base.

New test verifyChainedTableOffset (in agc_shader_memory_tests --bindless, ctest agc_shader_bindless) is the
verifyPointerTableOffsetCarry shader with the second offset chained off the first (s_add_i32 s20, s19, 16 instead of
s_add_i32 s20, s18, imm); it checks that the image is planned as a table with the expected column and that keys 3 and 5
resolve the records written at those offsets.

Same idea as Mouhand-Kaddo's fork commit 29c7106 (never submitted as a pull request); written separately.

Tested

  • Windows 10 22H2, WinLibs GCC 15.2.0 r7, Release, AMD Radeon RX 6600 XT (driver 32.0.21045.11001), Ryzen 5 5600X.
  • agc_shader_memory_tests --bindless: passes with the change. With SplitImmediateAddend reverted to main, the new test
    fails with the title's error: GetImageResource dword 0 is not a valid runtime value; chain: LoadAddressU32@pc=0x0000003c(...).
  • Offline replay: 52 compile requests saved from Demon's Souls (PPSA01342 v01.004.000, US) that fail on main (bd58561)
    with GetImageResource dword 0 is not a valid runtime value (17 during boot, the rest after NEW GAME), including
    shader 0x2489bea00 stage 1 from Demon's Souls (PPSA01342): deterministic RenderJob deadlock on counter 0x0000000200553EE0 after main loop starts #7203's log. agc_shader_replay --prepare: main 0/52 (all 52 resource analysis failed: GetImageResource dword 0),
    this branch 52/52 prepared. The requests contain title code and are not attached.
  • In the title: on our machine Demon's Souls with this change (and other local changes listed in the bring-up thread)
    goes through character creation and the intro into gameplay (Outpost Passage).
  • Demon's Souls (PPSA01342): deterministic RenderJob deadlock on counter 0x0000000200553EE0 after main loop starts #7203 reports a RenderJob deadlock after these shader errors on an RTX 5060 Ti; whether the deadlock depends on them is
    not established (see the discussion there). This PR fixes the shader preparation; the reporter could check whether the
    deadlock remains.
  • python tools/check_conventions.py --base origin/main: all conventions checks passed.
  • Full ctest (BUILD_TESTING=ON, --parallel 6) on the RX 6600 XT: 1386 passed, 17 skipped, 5 failed. None of the five
    comes from this change:
    • agc_driver_lds_mixed_width_atomics (lane 0 read 0xdeadbeefdeadbeef, expected 0x00001ffffffff000) and
      agc_driver_layered_volume_vertex_no_gpl (slice 1 texel (0, 0) channel 0 is 64, expected 255) fail the same way, three
      runs out of three, with ResourceTracker.cpp from main; they fail on this GPU/driver without the change.
    • guest_kernel_sys times out after renaming a subdirectory; it links only libkernel, libkernel_sys and libc.
    • log_macros / log_macros_timestamps fail only in this local build: ccache's base_dir makes __FILE__
      ..\..\...\tests\LogMacros.cpp, so the line starts with tests\LogMacros.cpp instead of tests/LogMacros.cpp.
      Built from the absolute path, the same test passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none (related: Demon's Souls (PPSA01342): deterministic RenderJob deadlock on counter 0x0000000200553EE0 after main loop starts #7203)
  • Unblocks: PPSA01342 Demon's Souls (PPSA01341) #1283
  • GPUs tested: AMD Radeon RX 6600 XT (RDNA 2), Windows 10 22H2, driver 32.0.21045.11001 (Adrenalin 26.9.2)
  • AI-assisted: yes

🤖 Generated with Claude Code

… offsets

SplitImmediateAddend peeled a single immediate operand off a T# dword's
scalar offset. A title that loads a 32-byte record with two
s_load_dwordx4, the second at soffset (first soffset + 16) where the
first is (key << 5) + C, left IAdd32(key << 5, C) as the base of dwords
4-7, which never matched dword 0's base, and the image failed with
"GetImageResource dword 0 is not a valid runtime value".

Peel immediate IAdd32 operands until none is left and sum them modulo
2^32, as the scalar adds do. The chained offsets then reach the existing
folded-addend path. verifyChainedTableOffset is the pointer table offset
carry shader with the second offset chained off the first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 18, 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 6232 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L1906, L5309, L5340
PR 6243 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L1906, L5309
PR 6440 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L1906, L5309, L5340
PR 6454 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L1906, L5309
PR 6488 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L1906, L5309, L5340

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 1341 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 4339 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 5371 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 5500 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 5958 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 6094 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6177 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6222 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6235 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6412 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6635 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6645 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6946 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6947 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6973 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6987 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6989 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6995 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 7002 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 7193 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 7223 core/shader/recompiler/Optimization/src/ResourceTracker.cpp

@oneandonlydean
oneandonlydean merged commit f1af6c5 into boykopovar:main Oct 18, 2026
2 checks passed
oneandonlydean pushed a commit that referenced this pull request Oct 18, 2026
Main's #7325 adds verifyChainedTableOffset to the image table tests
where this branch adds its selected-record tests. Keep both, with
main's call after this branch's.
adriadam10 pushed a commit that referenced this pull request Oct 19, 2026
#6243's new head merges main f1af6c5, whose #7325 adds
verifyChainedTableOffset next to the selected-record tests this
branch carries from #6243. That test reads the record words from the
snapshot's shared word list; this branch keeps the words with each
table's snapshot, so the merge reads them from the table it checks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants