fix(shader): plan a table T# that several image operations share #5550

Merged
milescoviello merged 2 commits from upstream-pr/5550 into main 2026-10-14 10:56:58 +00:00
milescoviello commented 2026-10-13 23:39:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-13T23:39:17Z.


What

Crimson Desert (PPSA25286) stops at start-up while it prepares one of its vertex programs:

Shader 0x20ac0f4100 could not be prepared after registration: shader 0x20ac0f4100 stage 1: ShaderRecompiler::Recompile: GetImageResource dword 0 is not a valid runtime value; chain: ReadConstBuffer@pc=0x0000043c(GetBufferResource(...), ShiftLeftLogical32(ReadFirstLane(SelectU32(...)), Immediate))

The program reads a T# from a descriptor table at a wave-uniform key and uses it twice:

0x434  v_readfirstlane_b32   vcc_lo, v4
0x438  s_lshl_b32            vcc_lo, vcc_lo, 5
0x43c  s_buffer_load_dwordx8 s[0:7], s[16:19], vcc_lo
0x448  image_get_resinfo     v1, v1, s[0:7]
0x47c  image_sample_lz       v6, v[0:1], s[0:7], s[24:27]

TryMakeTableImage already plans this shape (32-byte entries, a uniform key) as a bindless image table. It refused this one because it requires the eight scalar reads to have no user other than the one GetImageResource it is planning. SplitDescriptorPhis runs first. When it finds a Phi in the chain behind a T#, here in the lane condition of the v_cndmask_b32 that builds the key, it gives each image operation its own copy of the GetImageResource over the same eight reads. The query and the sample therefore have two handles, each read has two users, and the table is refused. GetHandle then rejects the scalar reads with the message above.

A read now passes the check when every user is a GetImageResource built from exactly these eight reads. Each copy is planned as the same table. Both get the same descriptor source, so the query and the sample share one table image and one set of slots.

agc_shader_bindless gains a case for this: a loop whose counter is part of the key, with image_get_resinfo and image_sample_lz on the same table T#. The loop Phi makes the split give the two operations separate copies, as in the title. The case checks that the plan has one table source and one image for both operations, that the capture binds the table slots, and that the program compiles to valid SPIR-V.

Instructions of the new case, after the four s_load_dwordx4 the existing wholeCode starts with:

s_mov_b32 s40, 0
v_mov_b32 v2, 0
loop:
v_readfirstlane_b32 s16, v0
s_add_u32 s16, s16, s40
s_lshl_b32 s16, s16, 5
s_buffer_load_dwordx8 s[20:27], s[4:7], s16
image_get_resinfo v[4:7], v2, s[20:27] dmask:0xf dim:2D
image_sample_lz v[8:11], v[0:1], s[20:27], s[8:11] dmask:0xf dim:2D
s_add_u32 s40, s40, 1
s_cmp_lt_u32 s40, 2
s_cbranch_scc1 loop
buffer_store_dword v8, off, s[28:31], 0
buffer_store_dword v4, off, s[28:31], 0 offset:4
s_endpgm

#5188 also targets GetImageResource dword 0 is not a valid runtime value, for a T# read at an offset the CPU walk can evaluate. With #5188 applied, the title still stops on this shader, because its key is not one the walk can evaluate. #5089 changes the same file for per-lane T#s in waterfall loops, and #1184, #757, #758 and #4475 extend the table planning. tools/pr_overlap.py --branch finds no overlap with any of them.

Tested

Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on main 7a0c838ca:

  • With main's ResourceTracker.cpp and the new case, agc_shader_bindless fails with the title's message, GetImageResource dword 0 is not a valid runtime value; chain: ReadConstBuffer@pc=0x00000034(...). With the change it passes.
  • All 500 tests in libSceAgcDriver pass on an RTX 4070 Ti (NVIDIA 580.142), the shader and driver tests included. agc_driver_stencil_ref_export is skipped, as on main, because the device lacks VK_EXT_shader_stencil_export.
  • The title's recompile request, replayed with agc_shader_replay, fails resource analysis with the message above on main. With the change, --prepare produces 36,023 SPIR-V words.
  • Crimson Desert (PPSA25286), relinked with --to-intel and run on Linux. Both runs include #5464, #3925 and #5523, which get the title past its earlier stops, and differ only in ResourceTracker.cpp:
    • Without the change it stops 7 s in on this shader (Shader 0x20ac0f4100 could not be prepared after registration).
    • With the change no shader fails to prepare. It runs to 18 s and stops on the next unsupported feature, VGT_SHADER_STAGES_EN=0x60212d: combined tessellation and geometry is unsupported by the reference path.
  • A MinGW-w64 GCC 13 -fsyntax-only -Wall -Wextra compile of both changed files has no errors. Its warnings, -Wclass-memaccess from IrValue.hpp and -Wmissing-field-initializers in the test file, are the same on main.
  • tools/check_conventions.py --base upstream/main passes.
  • @xXPBSXx ran it on Windows: Windows 10 (19045), MinGW-w64 GCC 15.2, Release, this PR merged onto main 34355eeea. agc_shader_bindless and agc_shader_memory pass in 3 runs each; that run had no baseline without the change.

Not checked on a console.

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
  • Unblocks: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4850862757 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5550). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-13T23:39:17Z. --- ### What Crimson Desert (PPSA25286) stops at start-up while it prepares one of its vertex programs: ``` Shader 0x20ac0f4100 could not be prepared after registration: shader 0x20ac0f4100 stage 1: ShaderRecompiler::Recompile: GetImageResource dword 0 is not a valid runtime value; chain: ReadConstBuffer@pc=0x0000043c(GetBufferResource(...), ShiftLeftLogical32(ReadFirstLane(SelectU32(...)), Immediate)) ``` The program reads a T# from a descriptor table at a wave-uniform key and uses it twice: ``` 0x434 v_readfirstlane_b32 vcc_lo, v4 0x438 s_lshl_b32 vcc_lo, vcc_lo, 5 0x43c s_buffer_load_dwordx8 s[0:7], s[16:19], vcc_lo 0x448 image_get_resinfo v1, v1, s[0:7] 0x47c image_sample_lz v6, v[0:1], s[0:7], s[24:27] ``` `TryMakeTableImage` already plans this shape (32-byte entries, a uniform key) as a bindless image table. It refused this one because it requires the eight scalar reads to have no user other than the one `GetImageResource` it is planning. `SplitDescriptorPhis` runs first. When it finds a Phi in the chain behind a T#, here in the lane condition of the `v_cndmask_b32` that builds the key, it gives each image operation its own copy of the `GetImageResource` over the same eight reads. The query and the sample therefore have two handles, each read has two users, and the table is refused. `GetHandle` then rejects the scalar reads with the message above. A read now passes the check when every user is a `GetImageResource` built from exactly these eight reads. Each copy is planned as the same table. Both get the same descriptor source, so the query and the sample share one table image and one set of slots. `agc_shader_bindless` gains a case for this: a loop whose counter is part of the key, with `image_get_resinfo` and `image_sample_lz` on the same table T#. The loop Phi makes the split give the two operations separate copies, as in the title. The case checks that the plan has one table source and one image for both operations, that the capture binds the table slots, and that the program compiles to valid SPIR-V. Instructions of the new case, after the four `s_load_dwordx4` the existing `wholeCode` starts with: ``` s_mov_b32 s40, 0 v_mov_b32 v2, 0 loop: v_readfirstlane_b32 s16, v0 s_add_u32 s16, s16, s40 s_lshl_b32 s16, s16, 5 s_buffer_load_dwordx8 s[20:27], s[4:7], s16 image_get_resinfo v[4:7], v2, s[20:27] dmask:0xf dim:2D image_sample_lz v[8:11], v[0:1], s[20:27], s[8:11] dmask:0xf dim:2D s_add_u32 s40, s40, 1 s_cmp_lt_u32 s40, 2 s_cbranch_scc1 loop buffer_store_dword v8, off, s[28:31], 0 buffer_store_dword v4, off, s[28:31], 0 offset:4 s_endpgm ``` #5188 also targets `GetImageResource dword 0 is not a valid runtime value`, for a T# read at an offset the CPU walk can evaluate. With #5188 applied, the title still stops on this shader, because its key is not one the walk can evaluate. #5089 changes the same file for per-lane T#s in waterfall loops, and #1184, #757, #758 and #4475 extend the table planning. `tools/pr_overlap.py --branch` finds no overlap with any of them. ### Tested Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on `main` 7a0c838ca: - With `main`'s `ResourceTracker.cpp` and the new case, `agc_shader_bindless` fails with the title's message, `GetImageResource dword 0 is not a valid runtime value; chain: ReadConstBuffer@pc=0x00000034(...)`. With the change it passes. - All 500 tests in `libSceAgcDriver` pass on an RTX 4070 Ti (NVIDIA 580.142), the shader and driver tests included. `agc_driver_stencil_ref_export` is skipped, as on `main`, because the device lacks `VK_EXT_shader_stencil_export`. - The title's recompile request, replayed with `agc_shader_replay`, fails resource analysis with the message above on `main`. With the change, `--prepare` produces 36,023 SPIR-V words. - Crimson Desert (PPSA25286), relinked with `--to-intel` and run on Linux. Both runs include #5464, #3925 and #5523, which get the title past its earlier stops, and differ only in `ResourceTracker.cpp`: - Without the change it stops 7 s in on this shader (`Shader 0x20ac0f4100 could not be prepared after registration`). - With the change no shader fails to prepare. It runs to 18 s and stops on the next unsupported feature, `VGT_SHADER_STAGES_EN=0x60212d: combined tessellation and geometry is unsupported by the reference path`. - A MinGW-w64 GCC 13 `-fsyntax-only -Wall -Wextra` compile of both changed files has no errors. Its warnings, `-Wclass-memaccess` from `IrValue.hpp` and `-Wmissing-field-initializers` in the test file, are the same on `main`. - `tools/check_conventions.py --base upstream/main` passes. - @xXPBSXx [ran it on Windows](https://github.com/boykopovar/AnyPS5/pull/5550#issuecomment-6160159091): Windows 10 (19045), MinGW-w64 GCC 15.2, Release, this PR merged onto `main` `34355eeea`. `agc_shader_bindless` and `agc_shader_memory` pass in 3 runs each; that run had no baseline without the change. Not checked on a console. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/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] Unblocks: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-14 01:33:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T01:33:13Z.


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
#5620 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L926
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158888562 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5550#issuecomment-6158888562). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T01:33:13Z. --- <!-- 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 | |---|---|---|---| | #5620 | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` [L926](https://github.com/boykopovar/AnyPS5/blob/bfe3dfe87a98d20f72ea4ddb94079da13001401e/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L926) | | |
xXPBSXx commented 2026-10-14 03:23:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T03:23:11Z.


Windows test of #5550: Windows 10 (19045), MinGW-w64 GCC 15.2, Release, ninja -j 4, ctest called directly; ctest ran without -V, so the logs of the passing runs do not show which GPU, if any, the tests used (not verified). Tree: main 34355eeea + merge of PR head cd1757e03659f4a363e1b73a2d8a3711808e084b (local merge 3d6a86e14, no conflict). Logs: rtx5550_*_N.log, rtx5550_result.txt.
2 ctest targets, 3 runs each, exit code 0 in 6 of 6 runs: agc_shader_bindless, agc_shader_memory.
Not tested: that the new or changed tests fail without the change (no baseline run), other ctest targets, the AMD GPU unless named above, Linux, a title run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6160159091 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5550#issuecomment-6160159091). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-14T03:23:11Z. --- Windows test of #5550: Windows 10 (19045), MinGW-w64 GCC 15.2, Release, `ninja -j 4`, ctest called directly; ctest ran without `-V`, so the logs of the passing runs do not show which GPU, if any, the tests used (not verified). Tree: `main` `34355eeea` + merge of PR head `cd1757e03659f4a363e1b73a2d8a3711808e084b` (local merge `3d6a86e14`, no conflict). Logs: `rtx5550_*_N.log`, `rtx5550_result.txt`. 2 ctest targets, 3 runs each, exit code 0 in 6 of 6 runs: `agc_shader_bindless`, `agc_shader_memory`. Not tested: that the new or changed tests fail without the change (no baseline run), other ctest targets, the AMD GPU unless named above, Linux, a title run. AI-assisted (Claude Code).
milescoviello commented 2026-10-14 03:24:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T03:24:26Z.


Thanks, @xXPBSXx. I've added the Windows run to the description.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6160174483 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5550#issuecomment-6160174483). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-14T03:24:26Z. --- Thanks, @xXPBSXx. I've added the Windows run to the description. AI-assisted: yes
simonbronk commented 2026-10-14 10:26:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T10:26:28Z.


Title evidence: Onimusha: Way of the Sword (PPSA27836 01.000.001, RE Engine), Windows 11 Pro 26200, RTX 5070. On main 0b97f8b9f plus the start-up fixes listed in #5769, it stops preparing pixel programs that read their T# from 48-byte records at +16 (s_buffer_load_dwordx8 at key * 0x30), the key loaded through a readfirstlane inside a bit-mask loop:

GetImageResource dword 0 is not a valid runtime value; chain: ReadConstBuffer@pc=0x0000391c(..., IMul32(ReadConstBuffer@pc=0x00002f88(..., IMul32(ReadFirstLane(...), Immediate)), Immediate))

A later program reads the same table T# for two image operations. With #5620 and #5550 both merged, both pass and the title stops next at static bindless image capacity exceeded (#5720). Not run with only one of the two.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6166250574 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5550#issuecomment-6166250574). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-14T10:26:28Z. --- Title evidence: Onimusha: Way of the Sword (PPSA27836 01.000.001, RE Engine), Windows 11 Pro 26200, RTX 5070. On `main` 0b97f8b9f plus the start-up fixes listed in #5769, it stops preparing pixel programs that read their T# from 48-byte records at +16 (`s_buffer_load_dwordx8` at `key * 0x30`), the key loaded through a `readfirstlane` inside a bit-mask loop: ``` GetImageResource dword 0 is not a valid runtime value; chain: ReadConstBuffer@pc=0x0000391c(..., IMul32(ReadConstBuffer@pc=0x00002f88(..., IMul32(ReadFirstLane(...), Immediate)), Immediate)) ``` A later program reads the same table T# for two image operations. With #5620 and #5550 both merged, both pass and the title stops next at `static bindless image capacity exceeded` (#5720). Not run with only one of the two. AI-assisted: yes (Claude Code).
milescoviello commented 2026-10-14 10:27:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T10:27:50Z.


Thanks for the Onimusha run. The later program, with one table T# used by two image operations, is the shape this PR handles (the copies of GetImageResource that SplitDescriptorPhis makes over the same eight reads). The 48-byte records at +16 behind a bit-mask loop sound like #5620's part.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6166273765 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5550#issuecomment-6166273765). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-14T10:27:50Z. --- Thanks for the Onimusha run. The later program, with one table T# used by two image operations, is the shape this PR handles (the copies of `GetImageResource` that `SplitDescriptorPhis` makes over the same eight reads). The 48-byte records at +16 behind a bit-mask loop sound like #5620's part. AI-assisted: yes
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!5550
No description provided.