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

Merged
Cleverdee merged 1 commit from upstream-pr/7325 into main 2026-10-18 00:30:47 +00:00
Cleverdee commented 2026-10-17 23:43:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Cleverdee on 2026-10-17T23:43:32Z.


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 29c71064 (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 (bd5856170)
    with GetImageResource dword 0 is not a valid runtime value (17 during boot, the rest after NEW GAME), including
    shader 0x2489bea00 stage 1 from #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).
  • #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: #7203)
  • Unblocks: PPSA01342 #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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4904910736 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7325). Originally posted by [Cleverdee](https://github.com/Cleverdee) on 2026-10-17T23:43:32Z. --- ### 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 29c71064 (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` (bd5856170) with `GetImageResource dword 0 is not a valid runtime value` (17 during boot, the rest after NEW GAME), including `shader 0x2489bea00 stage 1` from #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). - #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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none (related: #7203) - [x] Unblocks: PPSA01342 #1283 - [x] GPUs tested: AMD Radeon RX 6600 XT (RDNA 2), Windows 10 22H2, driver 32.0.21045.11001 (Adrenalin 26.9.2) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-18 00:05:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T00:05:48Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6243514852 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7325#issuecomment-6243514852). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T00:05:48Z. --- <!-- pr-overlap --> 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](https://www.github.com/boykopovar/AnyPS5/pull/6232) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` [L1906](https://github.com/boykopovar/AnyPS5/blob/bf3b5d679d6509384cea5355e167fb66df00a37f/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L1906), [L5309](https://github.com/boykopovar/AnyPS5/blob/bf3b5d679d6509384cea5355e167fb66df00a37f/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L5309), [L5340](https://github.com/boykopovar/AnyPS5/blob/bf3b5d679d6509384cea5355e167fb66df00a37f/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L5340) | | | | [PR 6243](https://www.github.com/boykopovar/AnyPS5/pull/6243) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` [L1906](https://github.com/boykopovar/AnyPS5/blob/bf3b5d679d6509384cea5355e167fb66df00a37f/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L1906), [L5309](https://github.com/boykopovar/AnyPS5/blob/bf3b5d679d6509384cea5355e167fb66df00a37f/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L5309) | | | | [PR 6440](https://www.github.com/boykopovar/AnyPS5/pull/6440) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` [L1906](https://github.com/boykopovar/AnyPS5/blob/bf3b5d679d6509384cea5355e167fb66df00a37f/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L1906), [L5309](https://github.com/boykopovar/AnyPS5/blob/bf3b5d679d6509384cea5355e167fb66df00a37f/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L5309), [L5340](https://github.com/boykopovar/AnyPS5/blob/bf3b5d679d6509384cea5355e167fb66df00a37f/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L5340) | | | | [PR 6454](https://www.github.com/boykopovar/AnyPS5/pull/6454) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` [L1906](https://github.com/boykopovar/AnyPS5/blob/bf3b5d679d6509384cea5355e167fb66df00a37f/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L1906), [L5309](https://github.com/boykopovar/AnyPS5/blob/bf3b5d679d6509384cea5355e167fb66df00a37f/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L5309) | | | | [PR 6488](https://www.github.com/boykopovar/AnyPS5/pull/6488) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` [L1906](https://github.com/boykopovar/AnyPS5/blob/bf3b5d679d6509384cea5355e167fb66df00a37f/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L1906), [L5309](https://github.com/boykopovar/AnyPS5/blob/bf3b5d679d6509384cea5355e167fb66df00a37f/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L5309), [L5340](https://github.com/boykopovar/AnyPS5/blob/bf3b5d679d6509384cea5355e167fb66df00a37f/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#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](https://www.github.com/boykopovar/AnyPS5/pull/1341) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 4339](https://www.github.com/boykopovar/AnyPS5/pull/4339) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 5371](https://www.github.com/boykopovar/AnyPS5/pull/5371) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 5500](https://www.github.com/boykopovar/AnyPS5/pull/5500) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 5958](https://www.github.com/boykopovar/AnyPS5/pull/5958) | `core/shader/recompiler/Optimization/src/ResourceTracker.cpp` | | [PR 6094](https://www.github.com/boykopovar/AnyPS5/pull/6094) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6177](https://www.github.com/boykopovar/AnyPS5/pull/6177) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6235](https://www.github.com/boykopovar/AnyPS5/pull/6235) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6412](https://www.github.com/boykopovar/AnyPS5/pull/6412) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6635](https://www.github.com/boykopovar/AnyPS5/pull/6635) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6645](https://www.github.com/boykopovar/AnyPS5/pull/6645) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6946](https://www.github.com/boykopovar/AnyPS5/pull/6946) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6973](https://www.github.com/boykopovar/AnyPS5/pull/6973) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6987](https://www.github.com/boykopovar/AnyPS5/pull/6987) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6989](https://www.github.com/boykopovar/AnyPS5/pull/6989) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6995](https://www.github.com/boykopovar/AnyPS5/pull/6995) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 7002](https://www.github.com/boykopovar/AnyPS5/pull/7002) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 7193](https://www.github.com/boykopovar/AnyPS5/pull/7193) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 7223](https://www.github.com/boykopovar/AnyPS5/pull/7223) | `core/shader/recompiler/Optimization/src/ResourceTracker.cpp` |
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7325
No description provided.