fix(shader): decide each resource branch condition once per plan #11506

Merged
hugodearaujo merged 1 commit from upstream-pr/11506 into main 2026-11-02 10:28:47 +00:00
hugodearaujo commented 2026-10-26 17:37:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-26T17:37:10Z.


What

MayDecide (#8518) checks whether a resource block's branch condition can be decided at capture time. For LogicalAnd and LogicalOr it recurses into both operands, and every step starts with a full MayEvaluate. Nothing is kept between steps. A condition whose operands share their own operands is therefore walked once per path, and each level that reads the level before it twice doubles the work.

This PR keeps each value's answer: MayDecide takes a record of what it has already decided, and ExtractPlan passes one record for all of a plan's blocks. An answer doesn't depend on the block (MayDecide calls MayEvaluate without an active mask), so sharing the record doesn't change any result.

@JJenkx, this is the walk from #8518. Its answers are the same; they're just kept now.

Tested

  • Skyrim (PPSA03747 01.001.010), Linux, RX 9070 XT with RADV (Mesa 26.2.5), Release, X pressed every 30 s:
    • main 522e32e3b6, 3 runs: the menus run at 60 fps. On the New Game loading screen, frames stop between 140 and 151 s, and the screen stays black until the timeout. Nothing is printed, and APS5_STALL_WATCHDOG_SECS=15 reports no stalled queue.
    • The title's main thread uses a whole core while the other 58 threads sleep. gdb at 170, 180, 200 and 220 s finds it in sceAgcCreateInterpolantMapping → AgcDriverResolveShaderAbi → PrepareShader → ResourceMaterializer::ExtractPlan → MayDecide, 20 to 29 frames deep, under MayEvaluate.
    • A local print around PrepareShaderWithDiagnostics (not in this PR) counted 3,818 preparations. Only one didn't finish: shader 0x122151a400, whose request I saved.
    • main 5ed5427bac with this PR: the title gets past that point and stops at 155 s on guest cube texture descriptor holds fewer than 6 array slices (format 71, 512x512x5, ...). That's where it stopped on main 65ac1d3b50, before #8518 (see #10347).
    • main 5bdda3661e with this PR: the same, at 156 s. With the cube descriptor fix in #11507 as well, it plays its opening, the cart ride to Helgen, until the 420 s limit of the run.
    • main 88795ed448, this branch's base, with this PR: the same, at 161 s; with #11507 as well, the opening until the 420 s limit.
  • agc_shader_replay --prepare of the saved request, ANYPS5_NO_SHADER_CACHE=1: on main it was still running when I stopped it at 60 s. With this PR it takes 18 ms (3 runs).
  • agc_shader_memory, new verifyMayDecideSharedConditions: 64 levels, where each level's LogicalOr reads two LogicalAnds of the level before and a lane comparison. With only lane comparisons, MayDecide answers false. With a uniform conjunct at the bottom, it answers true. A shared record gives the same answers.
    • Red: with main's evaluator, the test times out at 60 s. With this PR it passes in 0.16 s.
  • Paired validation on main 88795ed448 and this head 0dc6d38295, same machine and GPU: Linux (Arch, kernel 7.2.11), AMD Radeon RX 9070 XT (gfx1201) with RADV, Mesa 26.2.5, GCC 16.2.1, Release. ctest -V with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Khronos validation layer 1.4.363; the loader logs Insert instance layer "VK_LAYER_KHRONOS_validation"), ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1, on the tests around resource plans and their branch conditions: agc_shader_memory, agc_shader_disk_cache, agc_driver_graphics, agc_driver_branch_past_endpgm, agc_driver_image_table, agc_driver_image_table_cache, agc_driver_image_table_cache_bounds, agc_driver_image_table_reuse, agc_driver_image_table_reuse_draw_pipeline, agc_driver_image_table_vouched_lookups, agc_driver_image_table_vouch_queued_draws, agc_driver_compute_table_calls, agc_driver_compute_fs_table_calls, agc_driver_vertex_table_read_order and agc_driver_vopc_compare_table.
    • main: 15 of 15 pass. This head: 15 of 15 pass.
    • Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS, and neither has a VUID- line.
  • tools/select_tests.py on main 88795ed448, ANYPS5_REQUIRE_VULKAN=1: 1,500 of the 1,501 selected tests pass. agc_driver_tessellation segfaults inside RADV, as it does on main here (#5444, Mesa 26.2.5).
  • tools/check_conventions.py passes.
  • Not tested on Windows or macOS.

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
  • Unblocks: PPSA03747 #11508 (gets past its New Game loading screen hang to the cube descriptor stop above)
  • GPUs tested: AMD Radeon RX 9070 XT (gfx1201), RADV Mesa 26.2.5, Arch Linux (kernel 7.2.11)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5021921631 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11506). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-26T17:37:10Z. --- ### What `MayDecide` (#8518) checks whether a resource block's branch condition can be decided at capture time. For `LogicalAnd` and `LogicalOr` it recurses into both operands, and every step starts with a full `MayEvaluate`. Nothing is kept between steps. A condition whose operands share their own operands is therefore walked once per path, and each level that reads the level before it twice doubles the work. This PR keeps each value's answer: `MayDecide` takes a record of what it has already decided, and `ExtractPlan` passes one record for all of a plan's blocks. An answer doesn't depend on the block (`MayDecide` calls `MayEvaluate` without an active mask), so sharing the record doesn't change any result. @JJenkx, this is the walk from #8518. Its answers are the same; they're just kept now. ### Tested - **Skyrim (PPSA03747 01.001.010)**, Linux, RX 9070 XT with RADV (Mesa 26.2.5), Release, X pressed every 30 s: - `main` 522e32e3b6, 3 runs: the menus run at 60 fps. On the New Game loading screen, frames stop between 140 and 151 s, and the screen stays black until the timeout. Nothing is printed, and `APS5_STALL_WATCHDOG_SECS=15` reports no stalled queue. - The title's main thread uses a whole core while the other 58 threads sleep. gdb at 170, 180, 200 and 220 s finds it in `sceAgcCreateInterpolantMapping` → `AgcDriverResolveShaderAbi` → `PrepareShader` → `ResourceMaterializer::ExtractPlan` → `MayDecide`, 20 to 29 frames deep, under `MayEvaluate`. - A local print around `PrepareShaderWithDiagnostics` (not in this PR) counted 3,818 preparations. Only one didn't finish: shader 0x122151a400, whose request I saved. - `main` 5ed5427bac with this PR: the title gets past that point and stops at 155 s on `guest cube texture descriptor holds fewer than 6 array slices (format 71, 512x512x5, ...)`. That's where it stopped on `main` 65ac1d3b50, before #8518 (see #10347). - `main` 5bdda3661e with this PR: the same, at 156 s. With the cube descriptor fix in #11507 as well, it plays its opening, the cart ride to Helgen, until the 420 s limit of the run. - `main` 88795ed448, this branch's base, with this PR: the same, at 161 s; with #11507 as well, the opening until the 420 s limit. - `agc_shader_replay --prepare` of the saved request, `ANYPS5_NO_SHADER_CACHE=1`: on `main` it was still running when I stopped it at 60 s. With this PR it takes 18 ms (3 runs). - `agc_shader_memory`, new `verifyMayDecideSharedConditions`: 64 levels, where each level's `LogicalOr` reads two `LogicalAnd`s of the level before and a lane comparison. With only lane comparisons, `MayDecide` answers false. With a uniform conjunct at the bottom, it answers true. A shared record gives the same answers. - Red: with `main`'s evaluator, the test times out at 60 s. With this PR it passes in 0.16 s. - Paired validation on `main` 88795ed448 and this head 0dc6d38295, same machine and GPU: Linux (Arch, kernel 7.2.11), AMD Radeon RX 9070 XT (gfx1201) with RADV, Mesa 26.2.5, GCC 16.2.1, Release. `ctest -V` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (Khronos validation layer 1.4.363; the loader logs `Insert instance layer "VK_LAYER_KHRONOS_validation"`), `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`, on the tests around resource plans and their branch conditions: `agc_shader_memory`, `agc_shader_disk_cache`, `agc_driver_graphics`, `agc_driver_branch_past_endpgm`, `agc_driver_image_table`, `agc_driver_image_table_cache`, `agc_driver_image_table_cache_bounds`, `agc_driver_image_table_reuse`, `agc_driver_image_table_reuse_draw_pipeline`, `agc_driver_image_table_vouched_lookups`, `agc_driver_image_table_vouch_queued_draws`, `agc_driver_compute_table_calls`, `agc_driver_compute_fs_table_calls`, `agc_driver_vertex_table_read_order` and `agc_driver_vopc_compare_table`. - `main`: 15 of 15 pass. This head: 15 of 15 pass. - Neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`, and neither has a `VUID-` line. - `tools/select_tests.py` on `main` 88795ed448, `ANYPS5_REQUIRE_VULKAN=1`: 1,500 of the 1,501 selected tests pass. `agc_driver_tessellation` segfaults inside RADV, as it does on `main` here (#5444, Mesa 26.2.5). - `tools/check_conventions.py` passes. - Not tested on Windows or macOS. ### 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 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] Fixes: none - [x] Unblocks: PPSA03747 #11508 (gets past its New Game loading screen hang to the cube descriptor stop above) - [x] GPUs tested: AMD Radeon RX 9070 XT (gfx1201), RADV Mesa 26.2.5, Arch Linux (kernel 7.2.11) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-26 17:47:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T17:47:13Z.

Review: CHANGES_REQUESTED


The focused regression evidence is useful: the new shared-condition test times out with the old evaluator and passes with this change, and the full selected suite reports the same RADV tessellation failure as main. The branch is based on current main (88795ed448), and local conventions plus git show --check pass.

Before approval, please add the paired AGC/shader-recompiler validation required by CONTRIBUTING.md: the same focused ctest -V run on current main (88795ed44801fa719eb2df990cbe1f11a1f9bd81) and this head (0dc6d3829544ec5b4933d59f3d2ef9819a703085), on the same machine/GPU, with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1. Please include the GPU vendor/model, driver and OS, confirm neither log reports the requested-layer-missing message, and compare new VUID- lines. The current PR description reports tools/select_tests.py results but not this exact paired validation, and hosted product/relinker checks are skipped.

I found no implementation defect in the memoization path; changes requested for the missing required validation record.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5656508436 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11506#pullrequestreview-5656508436). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T17:47:13Z. **Review:** CHANGES_REQUESTED --- The focused regression evidence is useful: the new shared-condition test times out with the old evaluator and passes with this change, and the full selected suite reports the same RADV tessellation failure as `main`. The branch is based on current `main` (`88795ed448`), and local conventions plus `git show --check` pass. Before approval, please add the paired AGC/shader-recompiler validation required by `CONTRIBUTING.md`: the same focused `ctest -V` run on current `main` (`88795ed44801fa719eb2df990cbe1f11a1f9bd81`) and this head (`0dc6d3829544ec5b4933d59f3d2ef9819a703085`), on the same machine/GPU, with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`. Please include the GPU vendor/model, driver and OS, confirm neither log reports the requested-layer-missing message, and compare new `VUID-` lines. The current PR description reports `tools/select_tests.py` results but not this exact paired validation, and hosted product/relinker checks are skipped. I found no implementation defect in the memoization path; changes requested for the missing required validation record.
MarcZX10 commented 2026-10-26 19:13:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T19:13:35Z.

Review: APPROVED


The requested paired validation is now documented with the same RX 9070 XT/RADV/Mesa setup on 88795ed448 and this head. Both focused runs pass (15/15); the loader confirms the validation layer was inserted, and neither log reports a missing layer or any lines. The reported suite failure is on the broader selected run only and is the same RADV tessellation segfault reproduced on . Applicable hosted checks (conventions, labels, eligibility, intake and report) pass; product/relinker jobs are skipped. I found no remaining blocking issue in the reviewed memoization change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5657636625 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11506#pullrequestreview-5657636625). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T19:13:35Z. **Review:** APPROVED --- The requested paired validation is now documented with the same RX 9070 XT/RADV/Mesa setup on 88795ed448 and this head. Both focused runs pass (15/15); the loader confirms the validation layer was inserted, and neither log reports a missing layer or any lines. The reported suite failure is on the broader selected run only and is the same RADV tessellation segfault reproduced on . Applicable hosted checks (conventions, labels, eligibility, intake and report) pass; product/relinker jobs are skipped. I found no remaining blocking issue in the reviewed memoization change.
MarcZX10 commented 2026-10-26 19:13:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T19:13:39Z.

Review: APPROVED


The requested paired validation is now documented with the same RX 9070 XT/RADV/Mesa setup on main 88795ed448 and this head. Both focused runs pass (15/15); the loader confirms the validation layer was inserted, and neither log reports a missing layer or any VUID- lines. The reported suite failure is on the broader selected run only and is the same RADV tessellation segfault reproduced on main. Applicable hosted checks (conventions, labels, eligibility, intake and report) pass; product/relinker jobs are skipped. I found no remaining blocking issue in the reviewed memoization change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5657637817 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11506#pullrequestreview-5657637817). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T19:13:39Z. **Review:** APPROVED --- The requested paired validation is now documented with the same RX 9070 XT/RADV/Mesa setup on main 88795ed448 and this head. Both focused runs pass (15/15); the loader confirms the validation layer was inserted, and neither log reports a missing layer or any VUID- lines. The reported suite failure is on the broader selected run only and is the same RADV tessellation segfault reproduced on main. Applicable hosted checks (conventions, labels, eligibility, intake and report) pass; product/relinker jobs are skipped. I found no remaining blocking issue in the reviewed memoization change.
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!11506
No description provided.