Skip to content

fix(shader): narrow a goto junction Phi to the arm its branch allows - #14636

Merged
adriadam10 merged 13 commits into
boykopovar:mainfrom
zaryabzip:fix/shader-goto-junction-phis-main
Nov 10, 2026
Merged

adriadam10 merged 13 commits into
boykopovar:mainfrom
zaryabzip:fix/shader-goto-junction-phis-main

Conversation

@zaryabzip

@zaryabzip zaryabzip commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What

A new pass, GotoPhiRefiner, removes a resource-planning stop that the structurizer's goto-variable junctions cause.

The problem. When the structurizer can't clone a region, it routes control through one junction block and a goto variable. That happens in routeThroughJunction for an entered region, and in routeLoopExits for a loop whose exits share no post-dominator. A value that differs between the routed paths becomes a Phi at the junction, next to the Bool Phi of the goto variable, and a branch on that Bool Phi then picks the next region. Below that branch only the arms whose goto value matches can arrive, but SSA keeps the whole Phi. A descriptor address read there is a Phi of the right pointer and the other paths' values. The SRT walk can't evaluate that, and the shader stops with GetImageResource dword 0 is not a valid runtime value.

What the pass does. It runs just before the SRT walk. If it replaces anything, dead code elimination runs again.

  • Facts. A two-way branch on a Bool Phi, outside a loop header, gives its single-predecessor targets a fact: that Phi is true or false. The fact holds in every block the target dominates. Since the junction dominates the branch, such a block can't be reached from the junction again without passing through the target.
  • Narrowing. Where a non-Phi instruction uses a non-Bool Phi of the same junction, the pass keeps only the arms whose incoming guard is a constant equal to the fact. It follows parallel guard Phis of nested junctions the same way. An arm with a guard that isn't constant is always kept. The operand is replaced only when a single value is left.
  • Soundness. The replacement must dominate the use. No block the narrowing relied on, nor the replacement's own block, may reach the use without passing through the junction. Uses by Phis are left alone.
  • Cost. Results are kept per set of facts, with the blocks they relied on, because the same junction Phis sit under many arms. Without that, the recursion is exponential on large shaders.
  • Rounds. One round follows at most 64 levels of chained junctions and guards. The pass repeats while a round replaces an operand, up to 32 rounds, so a use below a longer chain still narrows. freneza found such a use on PPSA01317, about 20 junctions deep.

The disk cache format moves to 68. A shader.md debt entry records which merges stay unnarrowed.

Where it showed up. In Little Nightmares (PPSA10737, discussion #6275), on main + #7395 + #9749 + #10000, compute shader 0x200c340000 stopped at pc 0x119b8. Its address merged the call site's constant-buffer values (0x444 + 8/0xc) with scratch values from the other linked callees. With this pass the shader prepares and the address is the call site's value. The title then stops in the driver, because the module is 6.2M words; that is #13538's problem. On plain main, this title's shaders stop earlier and still need #9749 and #10000, so this PR unblocks nothing on its own. The new test shows the case directly.

GotoJunctionDescriptor.cpp builds a 64-wide compute program:

  • a loop sets s[16:17] from user data s[4:5] and leaves early on s_cmp_eq_u32 s8, s6;
  • otherwise it overwrites them with an s_buffer_load_dwordx2 and loops;
  • each exit ends the program, so the two have no common post-dominator and routeLoopExits builds a goto-variable junction;
  • the early-exit block loads a T# through s[16:17] and runs image_load.

The test checks that one image is planned and that each of its eight dwords is read through the SRT from a LoadAddressU32 whose address is GetUserData of s4 and s5, not a Phi.

GotoJunctionGuards.cpp builds IR by hand and runs the pass directly. Each guard gets a check that fails when that guard is removed:

  • an arm whose goto guard isn't a constant must stay;
  • a nested junction's value that is recomputed between the junction and the use must not replace the Phi;
  • a use the junction can reach again without passing the goto branch gets no fact.

Two twin checks show the same shapes being narrowed when the guards allow it.

Overlap: git merge-tree against main and every open pull request finds conflicts only on the FormatVersion line of ShaderDiskCache.hpp, with the 19 open PRs that also move the disk-cache format. Following the ladder in #10846, this PR takes 68, the next free number: open PRs hold 51–52, 54, 56–60 and 62–67, with #8939 at 66 and #9457 at 67.

Tested

Windows 11 (WinLibs GCC 15.2.0) and Ubuntu 24.04 on WSL2 (GCC 13.3.0), on main f2d874c, at a commit with the same code and test as the head (only the debt entry's wording changed since).

  • New test agc_goto_junction_descriptor, 3 runs each:
    • On main with only the test, it fails 3 of 3 on both hosts with GetImageResource dword 0 is not a valid runtime value; chain: LoadAddressU32@pc=0x0000003c(GetAddressResource(Phi(GetUserData(Void), ReadConst(GetSrtResource, Immediate)), Phi(...)), ...).
    • At the head it passes 3 of 3 on both.
  • Guard tests agc_goto_junction_guards: pass 3 of 3 on both hosts. In a mutation check, removing each guard fails only its own check:
    • dropping non-constant-guard arms fails "non-constant guard";
    • skipping the relied-block reachability check fails "nested junction value after the junction";
    • dropping the fact condition fails "junction rerun before the use".
  • Recompiler CPU-side tests: 37 of 37 on both refs and both hosts.
  • agc_* suite, Windows only, RTX 3060 Laptop GPU, NVIDIA 617.42, ANYPS5_NO_SHADER_CACHE=1:
    • main: 1202 passed and 9 skipped, of 1211.
    • Head: 1203 passed and the same 9 skipped, of 1212. The one extra test is the new one.
  • Little Nightmares, offline (agc_shader_replay --prepare):
  • No warnings in the new or changed files. tools/check_conventions.py passes.
  • At the head 38fc459, after the stale-fact check was dropped:
    • both new tests pass 3 of 3 on Windows and WSL2, and the 37 CPU-side tests pass on both;
    • GotoPhiRefiner.cpp builds with no warnings;
    • removing the dominance condition fails "junction rerun before the use" and "non-constant guard".
  • Rerun after the main merge, by me at e92fa373fe, which contains main 4977f64052 (comment): on Windows (WinLibs GCC 15.2.0 r7, Release) and on WSL2 (GCC 13.3.0, Release), both agc_goto_junction tests pass, ctest -R shader passes 112 of 112 and 104 of 104, and the 37 CPU-side tests pass 37 of 37. The merge keeps FormatVersion 68 over main's 57.
  • PPSA01317 (01.710.000), by freneza, on Linux (Fedora 44) with an RTX 5070, on main 4977f64052 with the GPU pull requests listed in Gran Turismo 7 (PPSA01317) #4697 and limitCallees raised to 256 locally. These are agc_shader_replay --prepare replays of the 29 compute shaders that were refused, not a game run:
    • At e92fa373fe (comment), all 29 still stop with GetImageResource dword 0 is not a valid runtime value. In 28 of them, one use of the pointer Phi is narrowed, but a deeper use at pc 0x19420 is not, because one round stops at MaxRefinementDepth.
    • At 8e5b82d0f2 (comment), those 28 get past the refusal and stop on image resource limit exceeded (ShaderInfo::MaxImages, outside this PR), so none prepares yet. 0x120aed7f00 still stops at pc 0x19f8, which has a different cause. The mean replay time per shader went from 41 s to 51 s, with 7 replays in parallel. agc_goto_junction_guards passes 3 of 3 there.
  • Rerun with the repeated rounds, by me at 8e5b82d0f2 (comment). On Windows (WinLibs GCC 15.2.0 r7, Release) and on WSL2 (GCC 13.3.0, Release), both agc_goto_junction tests pass 3 of 3, ctest -R shader passes 112 of 112 and 104 of 104, and the 37 CPU-side tests pass 37 of 37. With e92fa373fe's GotoPhiRefiner.cpp, agc_goto_junction_guards fails only "deep junction chain" (Windows). No warnings in GotoPhiRefiner.cpp or GotoJunctionGuards.cpp.
  • Rerun after the main merge, by me at 1560cfdef0, which merges main 095ff72367 (comment). On Windows (WinLibs GCC 15.2.0 r7, Release) and on WSL2 (GCC 13.3.0, Release), each set run once: both agc_goto_junction tests pass, ctest -R shader passes 117 of 117 and 109 of 109, and the 37 CPU-side tests pass 37 of 37. The merge keeps FormatVersion 68 over main's 60. No warnings in GotoPhiRefiner.cpp, GotoJunctionDescriptor.cpp or GotoJunctionGuards.cpp.
  • Not tested: the new test with the shader cache on, since agc_add_default_test turns it off.

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: none
  • GPUs tested: NVIDIA GeForce RTX 3060 Laptop GPU, driver 617.42, Windows 11
  • AI-assisted: yes (Claude Code)

When the structurizer routes several regions through one junction, a
value that differs between them becomes a Phi at the junction, and the
goto variable that picks the next region becomes a Bool Phi beside it.
Below a branch on that Bool Phi only the arms whose goto value matches
the branch side can arrive, but the resource tracker still sees every
arm. A descriptor address that is the call site's value on the taken
side then merges with other callees' scratch values and cannot be
resolved (Little Nightmares' 0x200c340000, discussion boykopovar#6275).

GotoPhiRefiner runs before the SRT walk. For each operand below such a
branch it keeps the arms whose guard is a constant equal to the branch
side, following parallel guard Phis of nested junctions, and replaces
the operand when one value is left. The fact must hold on every path to
the use: the use is dominated by the branch's single-predecessor target
and is not reachable from the junction around it. The value must
dominate the use, and no block it relies on may reach the use without
passing the junction. Results are kept per fact set, since the same
junction Phis sit under many arms. The disk cache format moves to 66.
…ves to that exit's pointer

A loop whose two exits end the program separately has no common
post-dominator, so its exits are routed through a goto-variable
junction. The early exit leaves with s[16:17] set from user data s[4:5];
the latch exit leaves after a constant-buffer load overwrites them. The
early-exit block loads a T# through s[16:17] and reads an image, so its
address is the junction Phi unless the branch on the goto variable
narrows it. On main this stops with "GetImageResource dword 0 is not a
valid runtime value"; the test checks that all eight T# dwords are read
through s[4:5].
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for the detailed write-up. I went through GotoPhiRefiner.cpp and couldn't find an unsound replacement: the stale-fact check, the non-constant-guard rule and the "relied block can't reach the use without passing the junction" check together keep the narrowed value on the same junction instance.

Since the pass runs on every shader and rewrites any narrowable operand (not only descriptor chains), could you add negative tests that pin those three guards? Right now removing any one of them still passes agc_goto_junction_descriptor:

  1. A loop where the junction runs again between the branch and the use, so the fact is stale: nothing may be replaced (line 185).
  2. A junction Phi arm whose goto guard is not a constant: the Phi must stay (line 263).
  3. A nested-junction value whose block can reach the use without passing the outer junction: no replacement (line 206).

They can be IR-level checks like the existing test (planned resource count and operand shape). Also please check that disk-cache format 66 is still free when this lands, since another PR taking the same number would merge without a conflict.

Reviewed at dc12552.

@zaryabzip

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Thanks for the review. I'll add all three as negative tests:

  • a junction that runs again between the branch and the use (line 185);
  • an arm whose goto guard is not a constant (line 263);
  • a nested junction value whose block reaches the use without passing the outer junction (line 206).

Each test leaves its operand a Phi. Each will also be checked to fail when only its own guard is removed, so they pin the guards rather than just passing. I'll post the mutation results with the push.

The disk-cache format: 66 is still free today, since open PRs hold 51 to 65. I'll check again when this is about to land.

… tests

Each check builds IR by hand and runs GotoPhiRefiner directly. A junction Phi arm whose goto guard is not a constant must stay. A latch arm that is a nested junction value recomputed between the junction and the use must not replace the Phi. A use the junction can reach again without passing the goto branch gets no fact. The constant-guard and entry-value twins show the same shapes are narrowed when the guards allow it.
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

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
PR 6858 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 7085 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 7395 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 8939 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 9457 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 9508 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 9633 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 9749 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 9790 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 9889 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 9969 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 10351 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 12944 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 14032 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 14853 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 14871 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 15343 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 15548 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 15555 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 16472 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 16631 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 16812 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 16814 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 17056 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 17611 core/shader/recompiler/ShaderDiskCache.hpp L16

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/shader/recompiler/Recompiler.cpp
docs/dev/debt/shader.md
PR 5371 docs/dev/debt/shader.md
PR 5609 core/shader/recompiler/Recompiler.cpp
PR 5925 core/shader/recompiler/CMakeLists.txt
core/shader/recompiler/ShaderDiskCache.hpp
PR 6235 docs/dev/debt/shader.md
PR 6280 core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 6412 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 6416 core/shader/recompiler/ShaderDiskCache.hpp
PR 6488 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 6924 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 7642 core/shader/recompiler/CMakeLists.txt
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 7684 core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 8004 core/shader/recompiler/CMakeLists.txt
core/shader/recompiler/Recompiler.cpp
docs/dev/debt/shader.md
PR 9356 core/shader/recompiler/CMakeLists.txt
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 9387 core/shader/recompiler/CMakeLists.txt
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 9748 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 9852 core/shader/recompiler/ShaderDiskCache.hpp
PR 10049 core/shader/recompiler/ShaderDiskCache.hpp
PR 10193 core/shader/recompiler/CMakeLists.txt
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 10359 core/shader/recompiler/Recompiler.cpp
PR 10652 core/shader/recompiler/Recompiler.cpp
docs/dev/debt/shader.md
PR 10757 core/shader/recompiler/Recompiler.cpp
PR 11551 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 12316 docs/dev/debt/shader.md
PR 12324 core/shader/recompiler/CMakeLists.txt
core/shader/recompiler/Recompiler.cpp
PR 12828 core/shader/recompiler/CMakeLists.txt
core/shader/recompiler/Recompiler.cpp
PR 13928 core/shader/recompiler/CMakeLists.txt
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 13929 core/shader/recompiler/CMakeLists.txt
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 14212 docs/dev/debt/shader.md
PR 14377 docs/dev/debt/shader.md
PR 14944 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 15681 docs/dev/debt/shader.md
PR 16088 core/shader/recompiler/CMakeLists.txt
PR 16935 core/shader/recompiler/Recompiler.cpp
docs/dev/debt/shader.md

… dominance implies

A fact needs the branch target to dominate the use. The junction
dominates the branch, so entry reaches the junction without passing the
target; a path from the junction to the use that avoided the target would
then avoid it from entry too. The use is never stale where the target
dominates it, so the reachability walk per fact is dropped. The rerun
check of agc_goto_junction_guards now pins the dominance condition.
@zaryabzip

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Added in 10c6526 (GotoJunctionGuards.cpp, IR built by hand, the pass run directly), plus 38fc459. Two of the three guards are now pinned. The third turned out to be implied by its neighbour, so I removed it instead.

Mutation check. Each guard was removed locally, rebuilt and run on Windows with GCC 15.2:

Mutation Fails
non-constant-guard arm dropped (old lines 263-264) only "non-constant guard"
relied-block reachability skipped (old line 206) only "nested junction value after the junction"
!stale[position] removed (old line 185) nothing
the whole fact condition removed (facts everywhere) "junction rerun before the use" and "non-constant guard"

agc_goto_junction_descriptor passes under all of them.

Why !stale can't fail. A fact is added at a position P only when the branch target T dominates P, and T's only predecessor is the branch block B.

  • The guard Phi is defined in junction J and used in B's condition, so J dominates B, and B dominates T.
  • So entry reaches J without passing T: cut any path at its first J. T can't come before it, since every path to T passes J first.
  • If P were stale, some path from J would reach P without T. Putting the entry path in front would give a path from entry to P avoiding T, which contradicts T dominating P.
  • Your loop, where the junction runs again before the use, therefore never has a stale fact where T dominates the use: to reach the use after a rerun, control has to pass T again.

38fc459 drops the check and its reachability walk per fact. With it gone, the rerun check pins the dominance condition: without that condition, the fact reaches the use through the other branch. The positive test and the four other checks are unchanged.

@zaryabzip

Copy link
Copy Markdown
Contributor Author

Confirmed at 38fc459 on Windows (GCC 15.2) and WSL2 (GCC 13.3):

  • agc_goto_junction_guards and agc_goto_junction_descriptor pass 3 of 3 on each, and the 37 CPU-side recompiler tests pass on both.
  • GotoPhiRefiner.cpp builds with no warnings.
  • Removing the dominance condition fails "junction rerun before the use", plus "non-constant guard": without it, the false edge's fact reaches the true branch and drops the constant arm. So that condition is now pinned twice.

boykopovar#8939 now takes 66 and boykopovar#9457 67, and the same number in two PRs would
merge without a conflict.
@zaryabzip

Copy link
Copy Markdown
Contributor Author

@oneandonlydean You were right to ask about the format. #8939 moved to 66 on Oct 31, and #9457 is at 67. Two PRs with the same number would have merged without a conflict, so 5ab18d0 moves this one to 68. I read the FormatVersion of every open PR's head today: the numbers in use are 51–52, 54, 56–60 and 62–67, so 68 is free. I'll check again before this lands.

@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head 5ab18d0 merged onto main f2d874c · tested 2026-11-02 00:23 UTC · 27 min

GPU NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Vulkan 1.4.329
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 2,510 passed · 7 failed (0 new, 4 also fail on main, 3 unstable on main) · 46 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,563 of 3,168 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (944 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_pipeline_journal 120.1 s, ⚠️ agc_driver_graphics_maps_fallback 31.4 s, ⚠️ agc_driver_graphics 30.5 s
Unstable on main (3, these also failed in recent main runs on this machine; not counted against this PR)
agc_driver_pipeline_journal: failed in 1 of the last 10 main runs
agc_submit_progress: failed in 5 of the last 10 main runs
agc_submit_progress_no_timeline: failed in 7 of the last 10 main runs
Failing on main too (4, not counted against this PR)
agc_driver_dcc_keys_first_write
agc_driver_image_table
guest_mmap_executable
guest_socket_options_multicast
Validated but not compared (2, not in the main baseline's validation pass)
agc_goto_junction_descriptor
agc_goto_junction_guards
Validation IDs already present on main (5 IDs in 484 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (484 tests): agc_driver, agc_driver_address_passes, agc_driver_alias_copy_label, agc_driver_alpha_to_coverage, agc_driver_array_layer_target, agc_driver_bc_block_copy, agc_driver_bda_anchor_reads, agc_driver_bda_span_reads, and 476 more
VUID-vkCmdCopyImage-srcImage-01548 (7 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_sampling, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-vkCmdCopyImage-srcImage-01551 (7 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_sampling, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (1 test): agc_driver_prepared_exports
VUID-VkShaderModuleCreateInfo-pCode-08737 (1 test): agc_driver_image_sample_derivatives
Skipped (46)
agc_driver_bda_reads_shadowed_results: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_bda_reads_shadowed_results_per_build: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_sample_order_grid_reference: skipped, the device does not keep depth drawn at custom sample locations at those locations, even after a transition that names them: the composite of uniform renders holds the guest's depth in 0 of 3005 sloped samples, so no path can be compared with it bit for bit
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_import_settle_initial_dcc: skipped, the device has no deferred settle of host imports: imports under 1 MiB wait for one only on Windows
agc_pipeline_binary_vulkan: skipped, the device lacks VK_KHR_pipeline_binary
agc_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
guest_http_uri_locale: 
guest_net_ctl: skipped, the host has no IPv4 address
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_output_mode: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_resolution_status: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_wqhd_detection: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
video_out_flip_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_backtoback: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_controls: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip_in_order: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_dcc: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_deferred: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_main: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_fps_limit: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL
Reproduce
git fetch origin 5ab18d0ce2f9a4e44eb332d809872dcb671a041b f2d874c1fdccf781c0fa5d86619bb5dd8894b958
git checkout f2d874c1fdccf781c0fa5d86619bb5dd8894b958 && git merge --no-ff 5ab18d0ce2f9a4e44eb332d809872dcb671a041b
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 32 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 4 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings from the read; the guards test was built but did not run on Windows

This PR adds GotoPhiRefiner, a shader optimization that narrows a goto junction Phi to the arm its branch allows, wired into PrepareResourceProgram after the first dead-code pass. I read the new pass and its header in full, and the wiring. The Windows CTest run passed the descriptor test. The guards test was compiled and linked on Windows, but it is not in the CTest selection, so it has no hosted pass.

What I ran

  • Head 5ab18d0ce2f9a4e44eb332d809872dcb671a041b; base f2d874c1fdccf781c0fa5d86619bb5dd8894b958. 10 files, +638/-1: Optimization/src/GotoPhiRefiner.cpp (+293, new), Optimization/include/Optimization/GotoPhiRefiner.hpp (+20, new), Recompiler.cpp (+5), ShaderDiskCache.hpp (FormatVersion 50 to 68), the recompiler CMake line, two AGC driver test sources and their CMake fragments, and a debt line.
  • Read the refiner and header in full: the dominator computation, the reachability and the fact collection from single-predecessor conditional targets, the memoized restriction of junction Phis, and the replacement of non-Phi operands. Read the wiring in Recompiler.cpp: when the refiner replaces any operand, dead-code elimination runs again.
  • Test sources: read the function names only. GotoJunctionDescriptor.cpp (103 lines) and GotoJunctionGuards.cpp (197 lines) were not read in full.
  • Hosted, Windows CTest: 2 cases were selected. agc_goto_junction_descriptor (Test #1828) passed, and conventions_env_reference_test_a_name_the_pull_request_does_not_touch_is_not_reported (Test #182) passed. The log shows agc_goto_junction_guards_tests.exe linked, and it is not in the selection.
  • Conventions: two runs on this head. The run started at 20:59:13 was cancelled. A later run started at 20:59:28 completed with success.
  • Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed (no declared dependencies, no errors). ABI audit not applicable.
  • The test-quality helper flagged both new test sources as possibly unregistered. Each CMake fragment names its file by the relative path tests/…cpp, which the helper's literal match did not find. The Windows build compiled both.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed the latest run succeeded; an earlier run on the same head was cancelled
Mergeability and dependencies passed stack check: no declared dependencies, no errors
ABI audit not applicable no export changed
agc_goto_junction_descriptor (hosted, Windows) passed Test #1828
agc_goto_junction_guards_tests (hosted, Windows) built, not run linked, but not in the CTest selection
Refiner logic (read) passed by reading no blocking defect found in the read
Refiner results on the test inputs not verified test bodies not read
Relinkers and relinker-asan (hosted) passed macOS, Ubuntu and Windows relinkers succeeded
library-portability (hosted) passed
Linux build and runtime tests not run Linux is skipped on pull requests
Negative controls not run no local build; no PR-head code runs here
Read-only check output

Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. Stack check: passed, no declared dependencies, no errors. ABI audit: not applicable. Hosted: gh api repos/boykopovar/AnyPS5/commits/5ab18d0ce2f9a4e44eb332d809872dcb671a041b/check-runs, and the Windows job log.

Negative control

Not run here. A negative control needs a local build and run of the shader tests, and code from this head is not run here.

Findings

Blocking

None from the code read.

Non-blocking

  • Recompiler.cpp runs the refiner for every shader that goes through PrepareResourceProgram, so a defect would reach every shader that uses a goto junction. The only hosted pass is the descriptor test. The guards test (197 lines) was not in the Windows selection, so nothing hosted exercises the junction guards. A run of agc_goto_junction_guards_tests at this head would close that gap.

Sources

Not verified

  • The bodies of GotoJunctionDescriptor.cpp and GotoJunctionGuards.cpp.
  • The refiner's output on real game shaders, and on any input other than the hosted tests.
  • The guards test on any host (it was built on Windows and not run in CTest).

To get this to a good state

  • Run agc_goto_junction_guards_tests at this head in hosted CI. Nothing else blocking.

@zaryabzip

zaryabzip commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Both junction tests at the exact head 5ab18d0, merged into main 4569fe6, 3 runs each:

  • Windows 11, GCC 15.2.0: agc_goto_junction_guards passes 3 of 3 ("Goto junction guard tests passed"), and agc_goto_junction_descriptor passes 3 of 3.
  • WSL2 Ubuntu 24.04, GCC 13.3.0: the same, 3 of 3 each.

Why the hosted run skipped the guards test: on pull requests the Windows job runs the tests that tools/build_changed_guest_tests.py picks. That script picked both; the log lists agc_goto_junction_descriptor_tests and agc_goto_junction_guards_tests. But it writes CTest's -I selection file without a trailing newline, and CTest drops the last character of that file. So 0,0,0,1828,1829 ran tests #1828 and #182. That's why an unrelated conventions_env_reference_… test ran in place of the guards test. Every Windows PR run loses its last selected guest test this way. #14413 (roboterspinne) already fixes it.

…shader-goto-junction-phis-main

# Conflicts:
#	core/shader/recompiler/ShaderDiskCache.hpp
@zaryabzip

Copy link
Copy Markdown
Contributor Author

Merged current main into this branch as e92fa373fe to clear the FormatVersion conflict in ShaderDiskCache.hpp. main is now at 57, and this branch keeps 68, which is still above it. 68 is also still unused among open PRs: their heads use 58–63 and 66–76, with 68 only here. No other file needed a hand resolution. A rerun of the junction tests on the new main is queued.

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 7, 2026
@zaryabzip

Copy link
Copy Markdown
Contributor Author

Rerun at e92fa373fe, to check the merge of main 4977f64052. I built the branch as it is, since it already contains the current main, and both systems built the same tree, f2da408e44. The only conflict was FormatVersion in ShaderDiskCache.hpp, where main has 57 and the merge keeps this PR's 68. That hunk is the only difference from git's automatic merge. The PR's diff against main is still its own 10 files, with 682 insertions and 1 deletion.

Each set run once:

Tests Windows WSL2
agc_goto_junction_descriptor and agc_goto_junction_guards 2 of 2 2 of 2
ctest -R shader 112 of 112 104 of 104
The 37 recompiler CPU-side tests from the earlier runs 37 of 37 37 of 37
  • Windows 11 Home 25H2 (26200.9711), WinLibs GCC 15.2.0 r7 UCRT, CMake 4.3.1, Ninja 1.13.2, Release, with ANYPS5_GPU=3060 (RTX 3060 Laptop GPU) as in the earlier runs.
  • WSL2, Ubuntu 24.04.5 (kernel 6.18.54.1), GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1, Release.
  • Nothing was skipped on either system. The shader counts differ because 9 shader-cache path tests exist only on Windows (agc_shader_cache_housekeeping_*, agc_shader_prebuilt_discovery_*, agc_shader_disk_cache_long_paths and agc_shader_disk_cache_host_stderr), and agc_shader_cache_housekeeping_plain-long exists only on Linux.
  • Neither build has warnings in GotoPhiRefiner.cpp, Recompiler.cpp, ShaderDiskCache.hpp or the two new tests.

I ran no control this time, because the earlier runs covered it.

AI-assisted: yes (Claude Code)

@freneza

freneza commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Tested on PPSA01317 (01.710.000), Linux, RTX 5070, on a local branch of main 4977f64 with the GPU pull requests listed in #4697, including #9969 and this head (e92fa37). limitCallees is raised to 256 there, locally, so that the table call in these shaders links.

The same 29 compute shaders stay refused with GetImageResource dword 0 is not a valid runtime value, and none is resolved. This change does move 28 of them: without it their chains end at pc 0x3554 to 0x35b0, and with it at pc 0x19420 to 0x1947c. The other one, 0x120aed7f00, stays at pc 0x19f8.

The chain of 0x120aec1a00 with this change, shortened:

LoadAddressU32@pc=0x00019420(GetAddressResource(
  LoadAddressU32@pc=0x000191a0(GetAddressResource(
    Phi(
      Phi(Phi(ReadConstBuffer@pc=0x00000160, CompositeExtractU32x4), ReadConstBuffer@pc=0x00000160(GetBufferResource, ShiftLeftLogical32)),
      Phi(LoadAddressU32@pc=0x00002920(...), LoadAddressU32@pc=0x0000311c(...))
    ), ...

The pointer read at pc 0x191a0 is still a Phi of the record word and of two values loaded at pc 0x2920 and 0x311c. The same arms are in the chain without this change, which stops at pc 0x3554 instead. The printed chain cuts off below those two loads, so I can't tell what they read. I have not looked at why this read is not narrowed; pc 0x19420 may be in a linked table callee, which I have not confirmed.

@zaryabzip

Copy link
Copy Markdown
Contributor Author

Thanks @freneza, this is useful. When 28 chains move from pc 0x3554–0x35b0 to 0x19420–0x1947c, the pass has narrowed a junction Phi in each of those shaders. The walk used to stop at that merge, and it now gets past it to the next pointer read.

The pass only narrows when three conditions hold (the shader.md entry for GotoPhiRefiner lists them):

  • the Phi is a non-Bool Phi of a goto-variable junction;
  • the instruction using it is not itself a Phi, and it sits below a two-way branch on that junction's Bool goto Phi;
  • every other arm is excluded by a constant guard on every path to the use.

The Phi at pc 0x191a0 can miss any of these, and the chain alone doesn't show which:

  • Not a junction Phi. It could be an ordinary if/else or loop merge of the record word and the two loads at 0x2920 and 0x311c. The pass never touches those.
  • No branch fact at the use. That can happen if 0x19420 is in the linked table callee, as you suspected. The pass then has no fact to narrow on, because nothing on the paths into the callee branches on the goto Phi.
  • A guard that isn't a constant. That arm is kept on purpose.

If you can attach the capture of 0x120aec1a00 (the agc_shader_replay input), I'll check which case it is. If it's a junction this pass should narrow and doesn't, I'll fix that here. If it's one of the other cases, it gets a line in the debt entry, and a follow-up would need a different kind of narrowing.

I'll add your run to Tested as a partial result. On PPSA01317 with that stack, 28 of the 29 refused chains end later and none resolves. The PR doesn't claim to unblock PPSA01317.

AI-assisted: yes (Claude Code)

@freneza

freneza commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

One correction before the capture: comparing the full chains of 0x120aec1a00 without and with this PR, they are identical except for the read's two pcs (0x353c/0x3554 vs 0x191a0/0x19420). The same Phi tree is still the pointer at the new site, so the merge itself isn't resolved. If the pass narrowed the use at 0x353c, the Phi is a junction Phi and the difference is per use, which points to a missing fact at 0x19420. That's an inference. The chain also has Ballot and ReadFirstLane, so a loop may be involved, and the dominance and reachability refusals in Refined() are a further case.

A capture holds title code and guest memory, so I'd rather not attach it publicly. I'll run the replay locally and report the junction block, the facts at the use and the refusal reason.

@zaryabzip

Copy link
Copy Markdown
Contributor Author

@freneza agreed, and thanks for the correction. I overstated it in my last comment. The pass narrows per use. The use at 0x353c was narrowed, so the walk moves on. At 0x19420 the same Phi tree is read again unnarrowed, so there is no fact there, or Refined() turned one down. Keeping the capture private is fine. For the local run, these are the places where a use can lose its fact, at head e92fa373fe:

  • No fact (GotoPhiRefiner.cpp, the fact collection around line 173). A branch gives no fact if its terminator is marked loopHeader, if its condition isn't a Bool Phi, or if a target has more than one predecessor. A fact also only reaches blocks that the target dominates. With Ballot/ReadFirstLane and a loop in the chain, the first case fits well: the branch on the goto Phi may be the loop header's exit test.
  • A refused replacement (Refined(), around lines 196–204). The replacement's block must dominate the use and can't be the use's own block. No relied block may reach the use without passing the junction (ReachableAvoiding).
  • No single arm left (RestrictArms). An arm whose guard is neither a constant nor a parallel guard Phi of the same nested junction stops the narrowing.

Logging the fact count at the use's block and which of these returns nullptr would tell the cases apart. If it is the loop-header exclusion, I'd rather check that case properly here than relax it blind, since that is where a fact can stop being true on the next iteration.

AI-assisted: yes (Claude Code)

@freneza

freneza commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Thanks. I replayed the capture locally on 0x120aec1a00, and it's none of those cases. My missing-fact guess was wrong too.

It's the recursion limit. The use at 0x191a0 has 27 facts, including cond=3731053 on junction block 2866, and the use at 0x353c has that same fact. Its operand is a Phi on block 3867, so Refined() doesn't return nullptr: it replaces the operand with Phi 3731303 on block 2866. That Phi has the same IR id as the operand at 0x353c, which narrows to a plain value. So the walk sees the same Phi tree again because the narrowing descends about 20 chained junctions and hits MaxRefinementDepth = 64, which returns the Phi as it stands.

The loop-header exclusion isn't involved, and I changed no guard. On that request:

Variant Rounds Result Time
Head e92fa373fe's pass, in my stack 1 GetImageResource refusal 32 s
MaxRefinementDepth raised to 4096 1 0x191a0 narrows to the value at 0x353c; next stop image resource limit exceeded 40 s, with a diagnostic print
Depth left at 64, Refine repeated until nothing is replaced 8 (41359 replaced in round 1, 0 in round 8) same next stop 38 s, one print per round

I'd prefer the repeated pass: it keeps the recursion depth bounded, and every replacement still goes through the same Refined() checks. The depth reached also isn't in the memo key, so a result cut off by the limit can be reused. I haven't checked whether that changes anything here.

Limits: this is agc_shader_replay --prepare on this one shader, not a game run or the test suite, and on my stack rather than the PR alone. The other 27 shaders aren't captured yet. image resource limit exceeded comes from ShaderInfo::MaxImages (64), which is a separate limit, so this shader still won't prepare.

…es nothing

One round stops at MaxRefinementDepth, so a use below a long chain of
goto junctions was replaced only by a Phi part way down the chain, and
the SRT walk still met a merge. freneza found this on PPSA01317, where
a use about 20 junctions deep kept the full Phi tree. Run the pass
again, up to 32 rounds, while a round replaces an operand; each round
starts with fresh memos and every replacement goes through the same
checks.
@zaryabzip

Copy link
Copy Markdown
Contributor Author

@freneza thanks, that settles it. I took your repeated-pass variant: 8e5b82d0f2 runs the pass again, up to 32 rounds, while a round replaces an operand. The recursion limit stays at 64.

  • Memo key. Each round builds a new Refinement, so its memos start empty, and a result cut off by the limit is never carried into the next round. Within one round a cut result can still be reused, but that only makes the round replace less, and the next round picks up from the deeper Phi. One case is left: two arms that agree only past 64 levels. The round then replaces nothing, so the pass stops. The shader.md entry now says so.
  • Test. GotoJunctionGuards.cpp gains a "deep junction chain" check: a use below 48 chained junctions must narrow to the value that entered the first one. It needs two rounds. With e92fa373fe's pass, the use stops at a Phi part way down the chain, and only this check fails. I built the test natively from the IR sources and ran it both ways. The Windows and WSL2 runs are queued, and I'll add them to Tested.

If you rerun 0x120aec1a00 at 8e5b82d0f2 on your stack, I'd expect the next stop you got, image resource limit exceeded. That is ShaderInfo::MaxImages, which is outside this PR.

AI-assisted: yes (Claude Code)

@zaryabzip

Copy link
Copy Markdown
Contributor Author

Rerun at 8e5b82d0f2, which adds repeated refinement rounds and the "deep junction chain" check on top of e92fa373fe. I built the head as it is, and both systems built the same tree, cabec48708. The head contains main 4977f64052. main has since moved 301 commits to 5062ba1fa4. That merges without conflicts, but I didn't test the head merged with it.

Tests Windows WSL2
agc_goto_junction_descriptor and agc_goto_junction_guards, 3 runs 3 of 3 each 3 of 3 each
ctest -R shader, once 112 of 112 104 of 104
The 37 recompiler CPU-side tests, once 37 of 37 37 of 37
  • Windows 11 Home 25H2 (26200.9711), WinLibs GCC 15.2.0 r7 UCRT, CMake 4.3.1, Ninja 1.13.2, Release, with ANYPS5_GPU=3060 (RTX 3060 Laptop GPU).
  • WSL2, Ubuntu 24.04.5 (kernel 6.18.54.1), GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1, Release.
  • Nothing was skipped. As in the last rerun, the shader counts differ only because some shader-cache path tests exist on one platform.
  • Control, Windows: I put back e92fa373fe's GotoPhiRefiner.cpp and kept this head's test. Only GotoPhiRefiner.cpp and the generated ShaderCacheVersion.cpp were rebuilt. agc_goto_junction_guards then fails with one line, goto junction guards: deep junction chain: a junction Phi below 48 chained junctions was not narrowed to the value that entered the first one, and its other six checks pass. I restored the file afterwards.
  • Warnings: none in GotoPhiRefiner.cpp or GotoJunctionGuards.cpp on either system, and none in the control build. The remaining warnings are in files this PR doesn't touch.

AI-assisted: yes (Claude Code)

@freneza

freneza commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Thanks. I replayed all 29 captures on my stack with 8e5b82d0f2's pass, using agc_shader_replay --prepare. 28 get past the GetImageResource refusal and stop on image resource limit exceeded, as you expected. 0x120aed7f00 still stops at pc 0x19f8, so it has a different cause. None prepares yet. With e92fa373fe's pass, all 29 stop on GetImageResource.

The mean replay time per shader went from 41 s to 51 s, with 7 replays in parallel, so that's only a relative figure. agc_goto_junction_guards passes 3 of 3 on Fedora 44.

These are replays and that one test on my stack, not a game run, and not the PR alone.

@zaryabzip

Copy link
Copy Markdown
Contributor Author

@freneza thanks for running all 29. I've added both of your runs to Tested, including the replay time, 41 s to 51 s per shader with 7 in parallel. That cost is the extra rounds. Each round recomputes dominators and facts for the whole program; only the memos have to start fresh. If the time matters, the dominators and facts could be computed once and shared across rounds, since the pass only replaces operands and never changes the CFG. I'd keep that for a follow-up unless a reviewer wants it here.

0x120aed7f00 at pc 0x19f8 is outside what this pass covers. If you post its chain, I'll say whether it is a goto junction at all.

AI-assisted: yes (Claude Code)

@EagleBearerYS

Copy link
Copy Markdown
Contributor

@freneza, the image resource limit exceeded stop is main's limit of 64 images per shader. The check is ShaderInfo::MaxImages, in ResourceTracker's AddImage.

#10489 raises the limit to 128, and its refusal prints the count, as image resource limit exceeded (129 of 128). With it on your stack, a replay of those 28 Gran Turismo 7 (PPSA01317) shaders either gets past this check or stops there with that count.

On #9969 (ce65f49) plus this PR's 8e5b82d, #10489 (74407aa) conflicts in two places:

@freneza

freneza commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@zaryabzip thanks for adding the runs. The chain of 0x120aed7f00 at your head 8e5b82d0f2, from the replay, cut where it repeats:

LoadAddressU32@pc=0x000019f8(GetAddressResource(
  LoadAddressU32@pc=0x000019a0(GetAddressResource(
    ReadConstBuffer@pc=0x00000ac8(
      GetBufferResource(Phi(Phi(Phi, Phi), Phi(Phi, Phi)), Phi(Phi(Phi, Phi), Phi(Phi, Phi)),
                        Phi(Phi(Phi, Phi), Phi(Phi, Phi)), Phi(Phi(Phi, Phi), Phi(Phi, Phi))),
      ShiftLeftLogical32(IAdd32(ReadLane(WriteLane, Immediate), IMul32(ReadLane, IAdd32)), Immediate)),
    ...

Here the pointer comes from a constant-buffer read at pc 0xac8. Each of that buffer's four V# dwords is a nested Phi, and the offset is built from ReadLane/WriteLane. The printed chain stops at those Phis, so it doesn't show whether they belong to a goto junction.

@EagleBearerYS thanks. With MaxImages raised locally, the 28 shaders need exactly 77 images, so #10489's 128 would get them past that check. But they then become 33.9-35.2M-word modules. In the title, 0x120aec1a00 (30.8M words) was compiling in vkCreateComputePipelines for about 18 minutes in two runs, and then my memory guard stopped the process: once at 2.2 GB of available RAM, once with RAM and the 15 GB of swap both exhausted, on a 30 GB machine. Details are in #13538 (comment). So the image limit isn't what keeps these shaders from running here; module size is.

@zaryabzip

Copy link
Copy Markdown
Contributor Author

@freneza thanks. 0x120aed7f00 is outside this PR. A goto junction Phi gets narrowed only at a use below a branch on that junction's Bool goto Phi, and only when the other arms carry constant guards. Your chain has two parts that can't be resolved here:

  • The four V# dwords are trees of Phis. If they were junction Phis with a fact at pc 0xac8, this pass would have replaced them, so they are either ordinary merges or junction Phis with no constant guard there.
  • The offset is built from ReadLane/WriteLane and a multiply. Even with the V# resolved, the walk would need that offset as a constant.

Both need their own work, so I'll leave it out of this PR. On module size, thanks for the numbers in #13538. That's where it belongs.

AI-assisted: yes (Claude Code)

@zaryabzip

Copy link
Copy Markdown
Contributor Author

@XairRrR your approval is on an earlier head. Since then, 8e5b82d0f2 added one change:

  • GotoPhiRefiner::Refine now repeats the pass, up to 32 rounds, while a round still replaces an operand.
  • GotoJunctionGuards.cpp gains a "deep junction chain" check.
  • The shader.md entry gains one sentence.

freneza found the case on PPSA01317: a use about 20 junctions deep that one round left unnarrowed at the recursion limit. The rerun on Windows and WSL2 is in Tested, with the old pass as a control. If you have time, a quick look at that commit would help: it is 7 lines in GotoPhiRefiner.cpp plus the test.

AI-assisted: yes (Claude Code)

…shader-goto-junction-phis-main

# Conflicts:
#	core/shader/recompiler/ShaderDiskCache.hpp
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 8, 2026
@zaryabzip

Copy link
Copy Markdown
Contributor Author

Rerun after the main merge. This is the Windows and WSL2 run of 1560cfdef0, which merges main 095ff72367 into 8e5b82d0f2. Both systems built the head as it is, tree d590b01260. The merge's only conflict was FormatVersion in ShaderDiskCache.hpp, and the head keeps 68 over main's 60. Against main the PR still changes the same 10 files (721 insertions, 1 deletion). Apart from the old FormatVersion value on the main side, its changed lines are identical to 8e5b82d0f2's, so I ran no control this time.

Tests, run once Windows WSL2
agc_goto_junction_descriptor and agc_goto_junction_guards both pass both pass
ctest -R shader 117 of 117 109 of 109
The 37 recompiler CPU-side tests 37 of 37 37 of 37
  • Windows 11 Home 25H2 (26200.9711), WinLibs GCC 15.2.0 r7 UCRT, CMake 4.3.1, Ninja 1.13.2, Release, with ANYPS5_GPU=3060 (RTX 3060 Laptop GPU).
  • WSL2, Ubuntu 24.04.5 (kernel 6.18.54.1), GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1, Release.
  • Nothing was skipped. ctest -R shader has 5 more tests on each system than at 8e5b82d0f2, all from main: agc_shader_image_limits_table, _mixed and _refusals, shader_memory_decoder_tolerance and shader_operand_types. The two systems' counts still differ because some shader-cache path tests exist on only one platform.
  • Warnings: none in GotoPhiRefiner.cpp, GotoJunctionDescriptor.cpp or GotoJunctionGuards.cpp on either system. All the other warnings (7 on Windows, 8 on WSL2) come from compiling files this PR doesn't touch: PipelineLibrary.cpp, VulkanDevice.cpp, ShaderFusion.cpp, Signals.cpp and RequestSerializerTests.cpp, plus IrValue.cpp on WSL2.

AI-assisted: yes (Claude Code)

@adriadam10
adriadam10 merged commit a00ad03 into boykopovar:main Nov 10, 2026
15 of 17 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Re-read the changes since the approved head: 8e5b82d repeats GotoPhiRefiner up to 32 rounds while a round replaces an operand (the CFG is never changed, each round starts with fresh memos), and the new "deep junction chain" check pins the 48-junction case. The FormatVersion 68 is still above main's 60. The only red job is Windows guest_standard_streams (0xc0000409), a libc test this PR doesn't touch; merged.

oneandonlydean pushed a commit that referenced this pull request Nov 21, 2026
Takes main's FormatVersion 68 from #14636, which is above this branch's 63; the next commit gives this branch its own number.
oneandonlydean pushed a commit that referenced this pull request Nov 21, 2026
…at, 79

`main` moved to 68 with #14636, above this PR's 63, and 69 to 78 are held by open PRs, so this PR takes 79 and a cache written by another branch's recompiler is not read as this one's.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants