fix(shader): decide resource branch conditions from their uniform operand #8518

Merged
JJenkx merged 1 commit from upstream-pr/8518 into main 2026-10-23 18:50:38 +00:00
JJenkx commented 2026-10-20 14:44:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-20T14:44:18Z.


What

A resource block's branch condition was kept in the resource plan only when it was fully evaluable at capture. A VALU compare that feeds s_cbranch_vccz/s_cbranch_vccnz becomes LogicalAnd(<the lane's EXEC bit>, <compare>) in the IR, so the lane-mask operand made the whole condition unevaluable even when the compare reads only SRT/constant-buffer values. The plan then dropped the condition, both successors stayed active, and an image read in the skipped block had to have a valid T#. On hardware no lane executes that read.

Tetris Effect: Connected (PPSA07923) compute shader 0x200ae40000 loads a T# from SRT +0x80 behind v_cmp_neq_f32 vcc, 0, s8 (s8 from its constant buffer) and s_cbranch_vccz. When the title leaves that texture unbound it stores other constants at +0x80 (43700000 43070000 3b888889 ..., i.e. 240.0, 135.0, 1/240, ...) and the flag is 0.0, so the dispatch stopped with runtime image descriptor is invalid shortly after the main menu appeared.

  • LogicalAnd and LogicalOr in the SRT interpreter and in the SRT tape yield their result from one operand when that operand alone decides it (false for LogicalAnd, true for LogicalOr), whether or not the other operand is evaluable. When both are evaluable the result is unchanged.
  • ExtractPlan keeps a block condition that can be decided this way (MayDecide), not only one that is fully evaluable. A condition that does not decide at capture still keeps both successors active, as before.
  • FPUnordLessThanEqual32 and FPUnordGreaterThanEqual32 are evaluated beside their ordered counterparts. A compare against zero is translated as a compare of the magnitude against the smallest normal (CompareInstructions.cpp), so v_cmp_neq_f32 with a zero operand becomes FPUnordGreaterThanEqual32(|x|, min normal).

Tested

Linux 7.2.9-arch1-1, Ryzen 9 7950X, AMD Radeon RX 6650 XT, RADV Mesa 26.2.4.

  • New verifyLaneMaskGuardedDescriptorSources in agc_shader_memory: RDNA code that loads a mode word, guards an image sample with v_cmp_neq_f32_e64 vcc, 0, s16 and s_cbranch_vccz, and holds an invalid T#. With the change, the plan keeps the VCC condition; a mode of +0.0 or -0.0 leaves the T# null; 1.0 still refuses the invalid T# and reads a valid one. The test fails on main (the VCC branch around the image kept no condition) and passes with the change, including with APS5_VERIFY_SRT_TAPE=1 and APS5_VERIFY_SRT_COMPACT=1.

  • Focused tests on main 52f7807a55 and on this change based on it, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (loader confirmed inserting the layer; no was not found but was requested line): agc_shader_memory, agc_shader_disk_cache, agc_shader_control_flow*, agc_shader_srt_read_patching, agc_shader_table_snapshot_reuse, agc_shader_type_zero_image_materialization, agc_guarded_memory_loads, agc_driver_guarded_null_pointer, agc_driver_buffer_descriptor_runtime, agc_driver_prepared_shaders*, agc_shader_replay_*, agc_driver_graphics: 33/33 pass on both, 0 VUID- on both.

  • Full ctest -j8 with the same environment on both: 1702 tests, the same 5 failures on main and on the change (agc_driver_bda_device, agc_driver_guest_memory_lifetime, agc_driver_image_array_window_past_layer_limit, agc_driver_tessellation segfault, guest_named_shm_concurrency), and identical VUID- sets and counts (VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 x26, VUID-VkImageViewCreateInfo-usage-02275 x6, VUID-vkCmdCopyBuffer-srcBuffer-00118 x2, VUID-VkImageCreateInfo-imageCreateMaxMipLevels-02251 x2, VUID-vkResetFences-pFences-01123 x2).

  • PPSA07923 02.000.021 natively, with APS5_PLAYGO_UNLISTED_CHUNKS=installed (the dump has no PlayGo metadata). Main alone runs this title at about 2-4 FPS because host imports fail with VK_ERROR_INVALID_EXTERNAL_HANDLE and collapse the import budget, so the scene was not reachable in a bounded run; the runs below add #8091, which addresses that. The same scripted input reached the main menu and stopped at about 96-100 s with compute shader 0x200ae40000: runtime image descriptor is invalid in 4 of 4 runs on main + #8091 (also with #8077 added). With this change + #8091 the same input reached gameplay and ran to the 260 s and 450 s limits at about 60 FPS without the stop.

  • Not verified on a console: which lanes the title executes there. The change relies only on the compare's value: when it is false no lane takes the guarded block, whatever EXEC is.

  • Independent Windows data point (Windows 10 19045, MinGW GCC 15.2): the new test passes with the change and fails with the library files restored, 3 of 3 each (comment).

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: PPSA07923 (#8613)
  • GPUs tested: AMD Radeon RX 6650 XT, RADV Mesa 26.2.4, Linux 7.2.9-arch1-1
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4937498386 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8518). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-20T14:44:18Z. --- ### What A resource block's branch condition was kept in the resource plan only when it was fully evaluable at capture. A VALU compare that feeds `s_cbranch_vccz`/`s_cbranch_vccnz` becomes `LogicalAnd(<the lane's EXEC bit>, <compare>)` in the IR, so the lane-mask operand made the whole condition unevaluable even when the compare reads only SRT/constant-buffer values. The plan then dropped the condition, both successors stayed active, and an image read in the skipped block had to have a valid T#. On hardware no lane executes that read. Tetris Effect: Connected (PPSA07923) compute shader `0x200ae40000` loads a T# from SRT `+0x80` behind `v_cmp_neq_f32 vcc, 0, s8` (`s8` from its constant buffer) and `s_cbranch_vccz`. When the title leaves that texture unbound it stores other constants at `+0x80` (`43700000 43070000 3b888889 ...`, i.e. 240.0, 135.0, 1/240, ...) and the flag is 0.0, so the dispatch stopped with `runtime image descriptor is invalid` shortly after the main menu appeared. - `LogicalAnd` and `LogicalOr` in the SRT interpreter and in the SRT tape yield their result from one operand when that operand alone decides it (false for `LogicalAnd`, true for `LogicalOr`), whether or not the other operand is evaluable. When both are evaluable the result is unchanged. - `ExtractPlan` keeps a block condition that can be decided this way (`MayDecide`), not only one that is fully evaluable. A condition that does not decide at capture still keeps both successors active, as before. - `FPUnordLessThanEqual32` and `FPUnordGreaterThanEqual32` are evaluated beside their ordered counterparts. A compare against zero is translated as a compare of the magnitude against the smallest normal (`CompareInstructions.cpp`), so `v_cmp_neq_f32` with a zero operand becomes `FPUnordGreaterThanEqual32(|x|, min normal)`. ### Tested Linux 7.2.9-arch1-1, Ryzen 9 7950X, AMD Radeon RX 6650 XT, RADV Mesa 26.2.4. - New `verifyLaneMaskGuardedDescriptorSources` in `agc_shader_memory`: RDNA code that loads a mode word, guards an image sample with `v_cmp_neq_f32_e64 vcc, 0, s16` and `s_cbranch_vccz`, and holds an invalid T#. With the change, the plan keeps the VCC condition; a mode of +0.0 or -0.0 leaves the T# null; 1.0 still refuses the invalid T# and reads a valid one. The test fails on main (`the VCC branch around the image kept no condition`) and passes with the change, including with `APS5_VERIFY_SRT_TAPE=1` and `APS5_VERIFY_SRT_COMPACT=1`. - Focused tests on main `52f7807a55` and on this change based on it, with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (loader confirmed inserting the layer; no `was not found but was requested` line): `agc_shader_memory`, `agc_shader_disk_cache`, `agc_shader_control_flow*`, `agc_shader_srt_read_patching`, `agc_shader_table_snapshot_reuse`, `agc_shader_type_zero_image_materialization`, `agc_guarded_memory_loads`, `agc_driver_guarded_null_pointer`, `agc_driver_buffer_descriptor_runtime`, `agc_driver_prepared_shaders*`, `agc_shader_replay_*`, `agc_driver_graphics`: 33/33 pass on both, 0 `VUID-` on both. - Full `ctest -j8` with the same environment on both: 1702 tests, the same 5 failures on main and on the change (`agc_driver_bda_device`, `agc_driver_guest_memory_lifetime`, `agc_driver_image_array_window_past_layer_limit`, `agc_driver_tessellation` segfault, `guest_named_shm_concurrency`), and identical `VUID-` sets and counts (`VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605` x26, `VUID-VkImageViewCreateInfo-usage-02275` x6, `VUID-vkCmdCopyBuffer-srcBuffer-00118` x2, `VUID-VkImageCreateInfo-imageCreateMaxMipLevels-02251` x2, `VUID-vkResetFences-pFences-01123` x2). - PPSA07923 02.000.021 natively, with `APS5_PLAYGO_UNLISTED_CHUNKS=installed` (the dump has no PlayGo metadata). Main alone runs this title at about 2-4 FPS because host imports fail with `VK_ERROR_INVALID_EXTERNAL_HANDLE` and collapse the import budget, so the scene was not reachable in a bounded run; the runs below add #8091, which addresses that. The same scripted input reached the main menu and stopped at about 96-100 s with `compute shader 0x200ae40000: runtime image descriptor is invalid` in 4 of 4 runs on main + #8091 (also with #8077 added). With this change + #8091 the same input reached gameplay and ran to the 260 s and 450 s limits at about 60 FPS without the stop. - Not verified on a console: which lanes the title executes there. The change relies only on the compare's value: when it is false no lane takes the guarded block, whatever EXEC is. - Independent Windows data point (Windows 10 19045, MinGW GCC 15.2): the new test passes with the change and fails with the library files restored, 3 of 3 each ([comment](https://github.com/boykopovar/AnyPS5/pull/8518#issuecomment-6308290696)). ### 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] Fixes: none - [x] Unblocks: PPSA07923 (#8613) - [x] GPUs tested: AMD Radeon RX 6650 XT, RADV Mesa 26.2.4, Linux 7.2.9-arch1-1 - [x] AI-assisted: yes
JJenkx commented 2026-10-20 19:07:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-20T19:07:22Z.


Rebased onto main b85d972f42 (no conflicts). Re-ran on the rebased commit 1c9a522bef (RX 6650 XT, RADV Mesa 26.2.4, Linux 7.2.9) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: the same focused set passes 33/33 with no VUID-; full ctest -j8 runs 1719 tests with 4 failures (agc_driver_guest_memory_lifetime, agc_driver_image_array_window_past_layer_limit, agc_driver_tessellation segfault, guest_named_shm_concurrency), each of which also failed on main 75787d2f64 in the comparison above.

Bring-up discussion for the title this unblocks: #8613.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298965359 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8518#issuecomment-6298965359). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-20T19:07:22Z. --- Rebased onto main `b85d972f42` (no conflicts). Re-ran on the rebased commit `1c9a522bef` (RX 6650 XT, RADV Mesa 26.2.4, Linux 7.2.9) with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`: the same focused set passes 33/33 with no `VUID-`; full `ctest -j8` runs 1719 tests with 4 failures (`agc_driver_guest_memory_lifetime`, `agc_driver_image_array_window_past_layer_limit`, `agc_driver_tessellation` segfault, `guest_named_shm_concurrency`), each of which also failed on main `75787d2f64` in the comparison above. Bring-up discussion for the title this unblocks: #8613.
xXPBSXx commented 2026-10-21 04:47:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T04:47:46Z.


Windows data point for 1c9a522be merged onto main 05f999570 (clean, git merge-tree rc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release. ctest -N -R '^agc_shader_memory$' lists exactly that one test; ctest --no-tests=error -R '^agc_shader_memory$' was run three times per tree.

  • With the PR: passes 3 of 3 (2.8-3.6 s).
  • Same tree with the five non-test files of the PR (SrtEvaluator.hpp/.cpp, SrtTape.hpp/.cpp, ResourceMaterializer.cpp) restored to main (the new test cases kept): fails 3 of 3 (ordinary test failure, not a crash).
    Not tested: other platforms, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308290696 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8518#issuecomment-6308290696). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T04:47:46Z. --- Windows data point for `1c9a522be` merged onto `main` `05f999570` (clean, `git merge-tree` rc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release. `ctest -N -R '^agc_shader_memory$'` lists exactly that one test; `ctest --no-tests=error -R '^agc_shader_memory$'` was run three times per tree. - With the PR: passes 3 of 3 (2.8-3.6 s). - Same tree with the five non-test files of the PR (`SrtEvaluator.hpp/.cpp`, `SrtTape.hpp/.cpp`, `ResourceMaterializer.cpp`) restored to `main` (the new test cases kept): fails 3 of 3 (ordinary test failure, not a crash). Not tested: other platforms, a title run. AI-assisted (Claude Code).
Amoenus commented 2026-10-21 05:39:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-21T05:39:54Z.


Independent Windows composition validation of unchanged 1c9a522bef304eff3ec51d21b881101c411c6a38, with your authorship preserved.

  • Parent: qualified fork 2e844131db5603a86e1b967adb878625a0bc1638, incorporating main 7d7b097407. This is not a literal-main or original-PR-head run.
  • Test-only control c7ce2ceafb: the new fixture fails 3/3 at the VCC branch around the image kept no condition.
  • Candidate 962e14c1d9: range-diff matches your commit; the fixture is byte-identical to the control. agc_shader_memory passes 3/3 each in default, APS5_VERIFY_SRT_TAPE=1, APS5_VERIFY_SRT_COMPACT=1, and both verifiers together. Seven neighboring CPU groups pass 3/3: 33 CPU processes total.
  • Five existing GPU groups (guarded_null_pointer, guarded_direct_root, native_color_draw_recipe, native_fmask, native_depth_bda_clear) pass 3/3 on each physical RTX 5080 and Radeon Graphics: 30 GPU processes, no skips/timeouts/VUIDs/validation warnings/errors. The new uniform-VCC case itself is CPU capture proof; these GPU groups are neighboring regressions, not a new dedicated VCC device fixture.

Windows 11 Enterprise 26200, Ryzen 9950X3D, WinLibs GCC15.2.0 r7/UCRT Release, SPIRV-Tools ON; NVIDIA610.62 and AMD32.0.21036.18. Required Vulkan, disabled application shader cache/journal, verbose serial CTest, actual adapter and loaded Khronos1.4.363 confirmed. Full default Windows build and explicit libraries/relinker build pass. The trusted main-a07 conventions checker reports no errors, retaining four inherited debt-length warnings. Cppcheck/clang-tidy findings were reviewed at unchanged parent contexts; one inherited GCC negative-fixture warning remains in both control and candidate builds.

This adds composition/backend and two-vendor coverage alongside the earlier Windows main comparison; it does not establish a Sonic fix, full-suite result, performance gain or console semantics. AI-assisted: yes (Codex); author responsible.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308948791 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8518#issuecomment-6308948791). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-21T05:39:54Z. --- Independent Windows **composition** validation of unchanged `1c9a522bef304eff3ec51d21b881101c411c6a38`, with your authorship preserved. - Parent: qualified fork `2e844131db5603a86e1b967adb878625a0bc1638`, incorporating main `7d7b097407`. This is not a literal-main or original-PR-head run. - [Test-only control `c7ce2ceafb`](https://github.com/Amoenus/AnyPS5/commit/c7ce2ceafbbabb4b4074befe204bcff9e234a0de): the new fixture fails **3/3** at `the VCC branch around the image kept no condition`. - [Candidate `962e14c1d9`](https://github.com/Amoenus/AnyPS5/commit/962e14c1d96f7b04e4ed498aa5cdadb41ad3f27a): range-diff matches your commit; the fixture is byte-identical to the control. `agc_shader_memory` passes **3/3 each** in default, `APS5_VERIFY_SRT_TAPE=1`, `APS5_VERIFY_SRT_COMPACT=1`, and both verifiers together. Seven neighboring CPU groups pass 3/3: **33 CPU processes total**. - Five existing GPU groups (`guarded_null_pointer`, `guarded_direct_root`, `native_color_draw_recipe`, `native_fmask`, `native_depth_bda_clear`) pass 3/3 on each physical RTX 5080 and Radeon Graphics: **30 GPU processes**, no skips/timeouts/VUIDs/validation warnings/errors. The new uniform-VCC case itself is CPU capture proof; these GPU groups are neighboring regressions, not a new dedicated VCC device fixture. Windows 11 Enterprise 26200, Ryzen 9950X3D, WinLibs GCC15.2.0 r7/UCRT Release, SPIRV-Tools ON; NVIDIA610.62 and AMD32.0.21036.18. Required Vulkan, disabled application shader cache/journal, verbose serial CTest, actual adapter and loaded Khronos1.4.363 confirmed. Full default Windows build and explicit libraries/relinker build pass. The trusted main-a07 conventions checker reports no errors, retaining four inherited debt-length warnings. Cppcheck/clang-tidy findings were reviewed at unchanged parent contexts; one inherited GCC negative-fixture warning remains in both control and candidate builds. This adds composition/backend and two-vendor coverage alongside the earlier Windows main comparison; it does not establish a Sonic fix, full-suite result, performance gain or console semantics. AI-assisted: yes (Codex); author responsible.
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!8518
No description provided.