fix(recompiler): leave out descriptor sources behind a branch the capture decides #3952

Merged
xXPBSXx merged 5 commits from upstream-pr/3952 into main 2026-10-12 21:00:59 +00:00
xXPBSXx commented 2026-10-11 19:44:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T19:44:28Z.


What

A compute kernel can pick a buffer or an image path from a word of its SRT and read the same address as a V# in one path and as a T# in the other. Teardown (PPSA15246) has such a copy kernel; the recompiler validated the descriptor of the path the capture does not take and threw runtime image descriptor is invalid (details in #3701).

The machinery to leave such a source out already exists (IrResourcePlan::controlFlow and the active pass in EvaluateRuntimeSourcesImpl: an inactive source is bound as zero words and not validated), but nothing outside a unit test filled controlFlow. This PR fills it:

  • ResourceTracker records, per block, the descriptor sources the block uses, and builds controlFlow from the structured block terminators (blockInfo: true/false blocks and the branch condition). A block whose terminator is neither a plain nor a conditional branch (indirect branches, loop headers) keeps all its CFG successors, so no source is dropped for a path that cannot be decided.
  • controlFlow is only set when some source is used only behind a conditional branch; otherwise the plan is unchanged.
  • Several image instructions of different dimensions on the same T# address share one descriptor source, so a source stays active as soon as one of them is taken; the tracker therefore also records the images a block uses, and an image used only behind a branch the capture does not take is bound as a null descriptor and not checked against the T#.
  • A condition that reads memory that is not accessible makes the branch "not evaluable" (both paths stay active) instead of throwing.
  • New test verifyGuardedDescriptorSources in ShaderMemory.cpp: a T# behind a branch on an SRT word is left null when the branch skips it (even if it holds garbage), still read when the branch is taken, and still rejected when invalid and taken; and two image_stores of different dimensions on one T# in the two branches compile for the dimension that matches and fail for the one that does not. It fails without the change (the branch around the image was not planned, and without the image tracking incompatible with the static runtime image interface). docs/dev/TechnicalDebt.md lists the limits.

Tested

  • Windows, MinGW GCC 15.2.0, on main (a11c8f7f7): agc_shader_memory passes with the new case and fails without the change. 37 related tests pass (agc_shader_*, agc_structurizer, agc_scalar_select_mask, agc_driver_{bindless_images,compute_user_data_calls,guarded_null_pointer,oversized_descriptor_sets,scalar_*}, shader_buffer_address); agc_driver_oversized_dispatch was not built here, so not run. tools/check_conventions.py --base upstream/main passes.
  • Teardown with this branch plus #3824 and #3604: the runtime image descriptor is invalid stop and the following image descriptor is incompatible with the static runtime image interface stop are both gone; the copy kernel now compiles and the title runs on to sceNpTrophy2GetGroupInfo: invalid argument and AGC graphics: CMASK fast clears of a mipmapped, 3D or array color target are unsupported. Both are unrelated to this change.
  • Not tested: Linux, any other title, a branch whose condition needs the non-clean state (EXEC/VCC), or the pipeline cache across dispatches with different mode words (the mode word is a clean slot, which the existing reuse check compares; I did not exercise that).

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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4821820357 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3952). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-11T19:44:28Z. --- ### What A compute kernel can pick a buffer or an image path from a word of its SRT and read the same address as a V# in one path and as a T# in the other. Teardown (PPSA15246) has such a copy kernel; the recompiler validated the descriptor of the path the capture does not take and threw `runtime image descriptor is invalid` (details in #3701). The machinery to leave such a source out already exists (`IrResourcePlan::controlFlow` and the `active` pass in `EvaluateRuntimeSourcesImpl`: an inactive source is bound as zero words and not validated), but nothing outside a unit test filled `controlFlow`. This PR fills it: - `ResourceTracker` records, per block, the descriptor sources the block uses, and builds `controlFlow` from the structured block terminators (`blockInfo`: true/false blocks and the branch condition). A block whose terminator is neither a plain nor a conditional branch (indirect branches, loop headers) keeps all its CFG successors, so no source is dropped for a path that cannot be decided. - `controlFlow` is only set when some source is used only behind a conditional branch; otherwise the plan is unchanged. - Several image instructions of different dimensions on the same T# address share one descriptor source, so a source stays active as soon as one of them is taken; the tracker therefore also records the images a block uses, and an image used only behind a branch the capture does not take is bound as a null descriptor and not checked against the T#. - A condition that reads memory that is not accessible makes the branch "not evaluable" (both paths stay active) instead of throwing. - New test `verifyGuardedDescriptorSources` in `ShaderMemory.cpp`: a T# behind a branch on an SRT word is left null when the branch skips it (even if it holds garbage), still read when the branch is taken, and still rejected when invalid and taken; and two `image_store`s of different dimensions on one T# in the two branches compile for the dimension that matches and fail for the one that does not. It fails without the change (`the branch around the image was not planned`, and without the image tracking `incompatible with the static runtime image interface`). `docs/dev/TechnicalDebt.md` lists the limits. ### Tested - Windows, MinGW GCC 15.2.0, on `main` (`a11c8f7f7`): `agc_shader_memory` passes with the new case and fails without the change. 37 related tests pass (`agc_shader_*`, `agc_structurizer`, `agc_scalar_select_mask`, `agc_driver_{bindless_images,compute_user_data_calls,guarded_null_pointer,oversized_descriptor_sets,scalar_*}`, `shader_buffer_address`); `agc_driver_oversized_dispatch` was not built here, so not run. `tools/check_conventions.py --base upstream/main` passes. - Teardown with this branch plus #3824 and #3604: the `runtime image descriptor is invalid` stop and the following `image descriptor is incompatible with the static runtime image interface` stop are both gone; the copy kernel now compiles and the title runs on to `sceNpTrophy2GetGroupInfo: invalid argument` and `AGC graphics: CMASK fast clears of a mipmapped, 3D or array color target are unsupported`. Both are unrelated to this change. - Not tested: Linux, any other title, a branch whose condition needs the non-clean state (EXEC/VCC), or the pipeline cache across dispatches with different mode words (the mode word is a clean slot, which the existing reuse check compares; I did not exercise that). ### 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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-11 23:19:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:19:43Z.


EvaluateRuntimeSourcesImpl now catches the evaluator's runtime_error and goes on with both paths active (SrtDescriptorEvaluation.cpp:97-101). Catching an error to take another path isn't allowed here, and this one swallows every evaluator error, not only unreadable memory. Please drop the catch, or have the evaluator return "not evaluable" for that case without throwing and update the TechnicalDebt entry that says such a branch condition throws at record time.

The new comments in ShaderMemory.cpp (verifyGuardedDescriptorSources) need to go as well.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115030889 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3952#issuecomment-6115030889). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T23:19:43Z. --- `EvaluateRuntimeSourcesImpl` now catches the evaluator's `runtime_error` and goes on with both paths active (`SrtDescriptorEvaluation.cpp:97-101`). Catching an error to take another path isn't allowed here, and this one swallows every evaluator error, not only unreadable memory. Please drop the catch, or have the evaluator return "not evaluable" for that case without throwing and update the TechnicalDebt entry that says such a branch condition throws at record time. The new comments in `ShaderMemory.cpp` (`verifyGuardedDescriptorSources`) need to go as well.
xXPBSXx commented 2026-10-12 00:58:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T00:58:44Z.


Pushed the change you asked for: the catch is gone. Conditions are evaluated with a null-root sink on the clean evaluator, and a condition that read through a null user-data pointer is "not evaluable", so every successor stays active as before. The agc_shader_memory guarded-pointer case (null pointer chain) passes without any exception handling; TechnicalDebt wording updated (a pointer from user data that is not null still throws, as before).

Tested: agc_shader_memory, the agc|shader|srt ctest subset on Windows. Two unrelated failures: agc_write_tracking (fixed by #4131 on main, passes after merging main) and agc_driver_prepared_shaders_registered_workgroup_sync, which fails the same way with the control-flow planning disabled, so it is not caused by this PR.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115872917 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3952#issuecomment-6115872917). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T00:58:44Z. --- Pushed the change you asked for: the `catch` is gone. Conditions are evaluated with a null-root sink on the clean evaluator, and a condition that read through a null user-data pointer is "not evaluable", so every successor stays active as before. The `agc_shader_memory` guarded-pointer case (null pointer chain) passes without any exception handling; TechnicalDebt wording updated (a pointer from user data that is not null still throws, as before). Tested: `agc_shader_memory`, the `agc|shader|srt` ctest subset on Windows. Two unrelated failures: `agc_write_tracking` (fixed by #4131 on main, passes after merging main) and `agc_driver_prepared_shaders_registered_workgroup_sync`, which fails the same way with the control-flow planning disabled, so it is not caused by this PR. AI-assisted (Claude Code).
xXPBSXx commented 2026-10-12 01:14:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T01:14:40Z.


Follow-up: the unrelated registered_workgroup_sync failure is now tracked in https://github.com/boykopovar/AnyPS5/issues/4204 (it fails on clean main 7a84b2226 as well).

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116014106 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3952#issuecomment-6116014106). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T01:14:40Z. --- Follow-up: the unrelated `registered_workgroup_sync` failure is now tracked in https://github.com/boykopovar/AnyPS5/issues/4204 (it fails on clean main 7a84b2226 as well). AI-assisted (Claude Code).
xXPBSXx commented 2026-10-12 17:56:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T17:56:39Z.


Rebased onto main 2a5eca11c (no merge commits, head d7313bb69; same four commits as before). agc_shader_memory passes on Windows after the rebase. The review point about the catch was addressed in d7313bb69 (a null-root read in a condition now makes the condition not evaluable instead of throwing; TechnicalDebt entry adjusted); please re-check when you have time.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6129699390 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3952#issuecomment-6129699390). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T17:56:39Z. --- Rebased onto `main` `2a5eca11c` (no merge commits, head `d7313bb69`; same four commits as before). `agc_shader_memory` passes on Windows after the rebase. The review point about the `catch` was addressed in `d7313bb69` (a null-root read in a condition now makes the condition not evaluable instead of throwing; TechnicalDebt entry adjusted); please re-check when you have time. AI-assisted (Claude Code).
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!3952
No description provided.