fix(recompiler): split image reads whose T# or S# is a Phi of SRT reads #414

Merged
oneandonlydean merged 1 commit from upstream-pr/414 into main 2026-10-03 22:31:34 +00:00
oneandonlydean commented 2026-10-02 22:06:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T22:06:14Z.


What

A sampler or image chosen by scalar control flow reaches the image operation as a Phi of two SRT reads, for example Phi(ReadConst(GetSrtResource, 0x20), ReadConst(GetSrtResource, 0x30)) for the S#. The SRT walker accepts only invariant Phis, so GetHandle threw GetSamplerResource dword 0 is not a valid runtime value and the draw was skipped. In PPSA21564 this skips 2 to 3 G-buffer and HDR draws per level. On the world map, one of them leaves the screen almost entirely white while the map scrolls.

ResourceTracker now runs SplitDescriptorPhis before tracking. A read-only image operation (ImageSampleRaw, ImageGatherRaw, ImageQueryLod, ImageQueryDimensions, ImageRead) whose T# or S# dwords depend on non-invariant Phis of one block is copied once per distinct incoming descriptor:

  • each predecessor edge is grouped with the edges whose incoming values are equivalent, so two edges that carry the same descriptor share one copy;
  • each copy gets descriptor handles whose dwords are that edge's values, recomputed right before the operation. Only SRT reads with an immediate offset, user data, the shader base and pure uniform arithmetic over them are recomputed;
  • each copy after the first gets its own memory entry, so the host binds every edge's descriptor;
  • the copies' results are selected per component by a Bool Phi, in the Phi block, that is true for the edges of that copy.

The copies run where the original ran, under the same execution mask, so implicit derivatives are unchanged.

Any other shape is left alone and still throws as before:

  • Phis spread over more than one block, or a nested Phi;
  • an edge whose descriptor is not recomputable (a dynamic read, a VGPR value);
  • an image store or atomic.

Test: verifyDescriptorPhis in agc_shader_memory_tests builds compute programs that pick the S# (and, separately, the T#) with s_cbranch_scc1 between two SRT slots. It checks that the resource plan holds one resource per edge, that the SPIR-V samples once per edge (twice per edge for wave64 on a 32-wide host), that the captured snapshot holds both edges' descriptors, and that a variant whose second edge reads the S# at a register (SOFFSET) offset is still rejected with the old error.

Tested

  • Linux (CachyOS, GCC 16), RTX 4090: ctest 125/125 pass. With ResourceTracker.cpp reverted to main, agc_shader_memory_tests fails with GetSamplerResource dword 0 is not a valid runtime value; chain: Phi(ReadConst(GetSrtResource, Immediate), ReadConst(GetSrtResource, Immediate)).
  • PPSA21564, world map scene, 620 frames after the level starts, before and after on my integration branch:
    • the skipped draw (GetSamplerResource dword 0 is not a valid runtime value, chain Phi(ReadConst(GetSrtResource, Immediate), ReadConst(GetSrtResource, Immediate))) is gone;
    • washed-out frames (over 60% of pixels at luma 240 or more) while scrolling went from 16 of 49 to 3 of 49. I have not traced the remaining 3;
    • map FPS went from 11.9 to 10.8, with the previously skipped draws now running.
  • The change has been on my integration branch through repeated passes of my visual regression check (intro, title, menu and a level).

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 in TechnicalDebt
  • 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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4721969227 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/414). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-02T22:06:14Z. --- ### What A sampler or image chosen by scalar control flow reaches the image operation as a Phi of two SRT reads, for example `Phi(ReadConst(GetSrtResource, 0x20), ReadConst(GetSrtResource, 0x30))` for the S#. The SRT walker accepts only invariant Phis, so `GetHandle` threw `GetSamplerResource dword 0 is not a valid runtime value` and the draw was skipped. In PPSA21564 this skips 2 to 3 G-buffer and HDR draws per level. On the world map, one of them leaves the screen almost entirely white while the map scrolls. `ResourceTracker` now runs `SplitDescriptorPhis` before tracking. A read-only image operation (`ImageSampleRaw`, `ImageGatherRaw`, `ImageQueryLod`, `ImageQueryDimensions`, `ImageRead`) whose T# or S# dwords depend on non-invariant Phis of one block is copied once per distinct incoming descriptor: - each predecessor edge is grouped with the edges whose incoming values are equivalent, so two edges that carry the same descriptor share one copy; - each copy gets descriptor handles whose dwords are that edge's values, recomputed right before the operation. Only SRT reads with an immediate offset, user data, the shader base and pure uniform arithmetic over them are recomputed; - each copy after the first gets its own memory entry, so the host binds every edge's descriptor; - the copies' results are selected per component by a Bool Phi, in the Phi block, that is true for the edges of that copy. The copies run where the original ran, under the same execution mask, so implicit derivatives are unchanged. Any other shape is left alone and still throws as before: - Phis spread over more than one block, or a nested Phi; - an edge whose descriptor is not recomputable (a dynamic read, a VGPR value); - an image store or atomic. Test: `verifyDescriptorPhis` in `agc_shader_memory_tests` builds compute programs that pick the S# (and, separately, the T#) with `s_cbranch_scc1` between two SRT slots. It checks that the resource plan holds one resource per edge, that the SPIR-V samples once per edge (twice per edge for wave64 on a 32-wide host), that the captured snapshot holds both edges' descriptors, and that a variant whose second edge reads the S# at a register (SOFFSET) offset is still rejected with the old error. ### Tested - Linux (CachyOS, GCC 16), RTX 4090: `ctest` 125/125 pass. With `ResourceTracker.cpp` reverted to `main`, `agc_shader_memory_tests` fails with `GetSamplerResource dword 0 is not a valid runtime value; chain: Phi(ReadConst(GetSrtResource, Immediate), ReadConst(GetSrtResource, Immediate))`. - PPSA21564, world map scene, 620 frames after the level starts, before and after on my integration branch: - the skipped draw (`GetSamplerResource dword 0 is not a valid runtime value`, chain `Phi(ReadConst(GetSrtResource, Immediate), ReadConst(GetSrtResource, Immediate))`) is gone; - washed-out frames (over 60% of pixels at luma 240 or more) while scrolling went from 16 of 49 to 3 of 49. I have not traced the remaining 3; - map FPS went from 11.9 to 10.8, with the previously skipped draws now running. - The change has been on my integration branch through repeated passes of my visual regression check (intro, title, menu and a level). ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] 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!414
No description provided.