Skip to content

fix(shader): link table callees that read their program counter - #8140

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
tv7:fix/table-callee-getpc
Nov 1, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
tv7:fix/table-callee-getpc

Conversation

@tv7

@tv7 tv7 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

What

A compute shader that calls through a table (FindTableCalls / LinkCalls) is refused when one of the table's callees reads its program counter:

AGC driver: compute shader 0x11d049aa00 calls a target loaded from a table at program counter 0x2470, but user-data callee reads its program counter at callee offset 0x00000e34, which a linked copy does not keep

LinkCalls copies each callee into the caller, so an s_getpc_b64 inside the copy would return the copy's address instead of the callee's. For a table callee the original address is known (TableCallee::target), so the copy can keep the value the instruction reads on hardware:

  • LinkCalls expands each s_getpc_b64 s[n:n+1] of a table callee into s_mov_b32 s[n], lo and s_mov_b32 s[n+1], hi of target + offset + 4, the address the instruction returns at its original place. The callee's direct branches are re-targeted to the moved instructions, so the copy stays inside its call region.
  • UserDataCalleeLength takes allowGetpc; ReadTableCallees passes it, so table callees with s_getpc_b64 are read instead of refused. User-data callees (no fixed address at link time) are still refused as before.
  • A callee whose s_getpc_b64 writes something other than an SGPR pair, or that branches outside its own instructions, is refused with its own message.

Tested

Checklist

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 19, 2026
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

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 6188 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 6867 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 6977 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 7682 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 8592 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9432 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 11442 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp

@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Oct 20, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 20, 2026
@wachi35676

Copy link
Copy Markdown
Contributor

Windows 11 26300, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, main 02fb1ce53 with this PR (9a0bdcdde) merged. RTX 5070 Ti (617.42) and AMD Radeon iGPU 1002:13c0 (RDNA 2, AMD Windows driver 32.0.21042.62), ANYPS5_REQUIRE_VULKAN=1.

  • The value matches the ISA: RDNA 2 S_GETPC_B64 is D.u64 = PC + 4, and the expansion writes target + offset + 4.
  • scalar_call and the other call/swappc/user-data/shader-memory tests (ctest -R "scalar_call|swappc|user_data_call|table_call|shader_memory"): 9/9 pass. With LinkCalls inserting the callee unchanged (the expansion disabled, everything else from the PR kept), scalar_call fails.
  • Extra probe, not part of the PR: a backward branch onto an expanded instruction. The callee is s_getpc_b64 s[16:17]; s_cbranch_scc0 -2; s_setpc_b64 s[14:15] at 0x1122334400. Linked through TableCaller(), it gives s_mov_b32 s16, 0x22334404; s_mov_b32 s17, 0x11; s_cbranch_scc0 -5; s_setpc_b64 s[14:15] (0xbf84fffb): the branch lands on the first s_mov_b32, and BuildCode and TranslateCode accept it.
  • ctest -R "agc|shader|spirv|recomp|scalar_call" -j6, 834 tests: RTX, only agc_driver_pass_input_hazard fails, as on main here. iGPU: agc_driver_mul_lo_u16_high_half and agc_driver_sgpr_pattern_fill_keys fail as on main, plus agc_driver_queued_index_read_order, which passed 3 of 3 when run alone. No new failures.

No title here (no PPSA03671).

AI-assisted: yes (Claude Code); results above were run on this machine.

@MarcZX10

Copy link
Copy Markdown
Contributor

The new #10140 independently increases the ReadUserDataCallee read bound and changes its scan cadence for long callees. I tested the current PR heads with git merge-tree; they have a content conflict in ShaderRegistry.cpp at this function. The behaviors are distinct, but please coordinate merge order/integration with #10140 so both the allowGetpc behavior and the longer-callee handling are retained.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@tv7 since #9068 landed, this branch conflicts with main in GraphBuilder.cpp, in the table-callee linking, and I don't think it can be fixed by picking one side. #9068 rewrote that body: the callees are no longer appended after the table and reached with s_call_b64 offsets. Each one is now inlined in its own segment, followed by a branch back (back(callee)), with relay stations to keep the branches in range. The segment offsets (segments[]) are worked out from callees[callee].code.size() before anything is emitted. Your loop, with expandProgramCounterReads, belongs to the old layout.

To keep your fix on main's layout, I think the program-counter expansion has to happen before segments[] is computed, so the sizes and the branch targets account for the expanded code. The inlined code would then be the expanded copy (linked.insert(..., code.begin(), code.end()) where main inserts callees[callee].code). The value a callee reads as its PC also changes now that it runs inline in a segment, so target may no longer be the right base for the expansion. Could you merge main and rework it that way, then rerun ScalarCall and the table-link tests? I'd rather not resolve it in a merge commit, since it changes what the callee computes.

@frankea

frankea commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

@tv7 a merge-order note for this PR and #10140, which the review of #10140 paired: both change ReadUserDataCallee in ShaderRegistry.cpp, and git merge-tree reports a conflict in that function only.

  • This PR adds allowGetpc to ReadUserDataCallee and passes it to UserDataCalleeLength, true for table callees.
  • fix(agc): read user-data callees up to the 1 MiB raw shader program limit #10140 raises the read window from 16,384 dwords to the 1 MiB raw-program limit and checks for the return at doubling sizes, before an unreadable page and at the limit, through one finish lambda that calls UserDataCalleeLength.
  • The resolution keeps both: the new parameter, and finish passing allowGetpc to UserDataCalleeLength.

I'd propose this PR lands first, since it's the older one; after it does, I'll merge main into #10140 and carry allowGetpc through. If you'd rather #10140 went first, that works for me too, and I can post the resolved function for your branch.

AI-assisted: yes (Claude Code)

# Conflicts:
#	core/shader/recompiler/ControlFlow/src/GraphBuilder.cpp
@tv7

tv7 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

@oneandonlydean merged main (2fade7e) and reworked it on #9068's layout, as you described:

  • LinkCalls expands each table callee once, before segments[] is computed (codes[callee] = expandProgramCounterReads(...)), so the segment sizes, one()/back() and the relay stations are all worked out from the expanded code, and the segment inlines codes[callee] where main inserted callees[callee].code.
  • The old append-and-s_call_b64 loop is gone; nothing else in fix(shader): link table callees that together exceed s_call_b64 range #9068's body changed.

On the base: the s_getpc_b64 replacement writes target + pc + 4, the address the instruction has in guest memory. That is what the instruction returns on hardware, where the callee runs at target. The expansion is a constant, so it is the same wherever the linked copy sits, and anything the callee computes from it is a guest address, as on hardware. So target is still the right base: the inline segment moves the copy, not the value the callee expects. The branches inside the expanded callee are re-encoded relative to their new positions inside the callee, so they don't depend on where the segment starts.

Tests on the merge head (Windows, MinGW GCC 15.2, Release):

  • ScalarCall: passes. Negative control: with the segment sizes taken from the unexpanded code again (callees[callee].code.size()), scalar_call fails.
  • Full build + full ctest: 2159 of 2166 pass. The 7 that fail (shader_cache_runtime_sources, patched_libraries, agc_host_import_cut_lifetime, agc_driver_depth_plane_partial_store, guest_memory, patch_advisor_unit, patch_advisor_integration) fail the same way on plain main 2fade7e on this machine.

AI-assisted: yes (Claude Code)

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@tv7 thanks for the rework. Expanding each table callee once before segments[], so the segment sizes, one()/back() and the relay stations all come from the expanded code, looks right to us.

One test-only fix is needed before CI: in CheckTableCalleeProgramCounter (core/libs/tests/ScalarCall.cpp:402), RdnaInstructionDecoder{}.Decode(TableCaller()) decodes a temporary. RdnaProgram::code is a std::span, so program.code dangles by the time LinkCalls copies it. On Linux (GCC 16, Release) scalar_call fails at this head with VOP2 opcode is not implemented, and the linked caller words are garbage. Holding the caller in a local, as CheckTableCalls does, fixes it:

const auto caller = TableCaller();
const auto program = RdnaInstructionDecoder{}.Decode(caller);

With that change scalar_call passes here. It also fails, as it should, both with the old per-callee sizing and with the expansion disabled, so the test pins the rework.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
RdnaProgram::code is a span, so decoding the temporary TableCaller() left it dangling when LinkCalls copied the caller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tv7

tv7 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

@oneandonlydean thanks, you're right: the decoded program kept a span of the temporary. Pushed aa656b2: CheckTableCalleeProgramCounter now holds the caller in a local before decoding it, as CheckTableCalls does. scalar_call passes here (Windows, MinGW GCC 15.2, Release); the branch still merges cleanly with main cf528e7.

AI-assisted: yes (Claude Code)

@ahmadmuj ahmadmuj 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 head aa656b2ee5 merged onto main 0119103fa9 (clean merge). Linux x86_64 (WSL2), GCC 13.3, Release, lavapipe (llvmpipe, LLVM 20.1.2).

What I ran:

  • scalar_call, scalar_swappc, agc_shader_control_flow (plus _iteration_selection_off and _forced_fallback), agc_driver_compute_table_calls, agc_driver_compute_fs_table_calls, agc_driver_compute_user_data_calls (plus _registered), agc_driver_scalar_swappc: 10/10 pass. The driver table-call tests really ran on lavapipe, not skipped.
  • Red: LinkCalls with codes taken straight from callee.code (expansion off, rest of the PR kept): scalar_call fails. Back to the PR: passes.
  • tools/check_conventions.py --base 0119103fa9: pass.
  • Extra probe, not part of the PR: a callee where the s_getpc actually runs and feeds a PC-relative load, s_getpc_b64 s[16:17]; s_add_u32 s16, s16, 0x40; s_addc_u32 s17, s17, 0; s_load_dword s20, s[16:17], 0; s_waitcnt lgkmcnt(0); s_setpc_b64 s[14:15] at 0x1122334400, through TableCaller(). It links to s_mov_b32 s16, 0x22334404; s_mov_b32 s17, 0x11; ..., and BuildCode/TranslateCode accept it. The IR loads through GetAddressResource(s16, s17) after the add, so it reads guest 0x1122334444, same as on hardware.

Code walk:

  • target + pc + 4 matches the recompiler's own s_getpc_b64 model (sGetpcB64: shader base + pc + 4).
  • Branch remap: moved[] only marks instruction starts, so a branch into a literal throws, and branchWord gets expanded offsets on both ends. A branch past the return is already refused by UserDataCalleeLength.
  • A computed jump off the PC is still refused: s_setpc_b64 through anything but the link throws in UserDataCalleeLength.
  • Caching: the prepared-entry match compares the full linked code (ShaderRegistry.cpp, std::ranges::equal(..., linked.code)), and the baked literal is part of it, so same-byte callees at different addresses don't share a translation.
  • User-data callees still refuse s_getpc_b64 (default false).

One optional thing: in CheckTableCalleeProgramCounter the callee starts with s_branch +1 (0xbf820001), which jumps over the s_getpc. So the expanded s_mov pair is dead code when BuildCode/TranslateCode run on it. The word check and the red run still pin the expansion. If you want the translate step to cover a live expanded read too, a callee like the probe above would do: {0xbe901f00, 0x8010ff10, 0x00000040, 0x82118011, 0xf4000508, 0xfa000000, 0xbf8cc07f, 0xbe80200e}.

Not checked: the title (no PPSA03671), and the AMD ISA PDF itself (wachi35676 quoted it above; I compared against the existing translation instead).

@wachi35676

Copy link
Copy Markdown
Contributor

Windows re-run of the reworked head aa656b2ee5, merged onto main b90d009d9f (clean). Windows 11 10.0.26300, WinLibs GCC 15.2.0, Release, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1. GPUs: RTX 5070 Ti and the AMD RDNA2 iGPU (ANYPS5_GPU=AMD).

  • The call, swappc, user-data, table-call, agc_shader_control_flow and agc_shader_memory tests pass 12/12 on each GPU, 2 runs. With LinkCalls copying the callee unexpanded and the rest of the PR kept, scalar_call fails.
  • I redid my earlier probe on the new segment layout, plus two more cases, in CheckTableCalleeProgramCounter:
    • A backward s_cbranch_scc0 -2 onto s_getpc_b64 s[16:17] becomes s_cbranch_scc0 -5 (0xbf84fffb). It lands on the first s_mov_b32, and BuildCode/TranslateCode accept it.
    • A literal-carrying s_mov_b32 s2, 0x12345678 after the s_getpc is copied intact.
    • Two s_getpc at +0 and +4 become 0x1122334404 and 0x1122334408, matching PC + 4 for each.

AI-assisted: yes (Claude Code); results above were run on this machine.

@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head aa656b2 merged onto main 52c09d5 · tested 2026-10-29 09:24 UTC · 28 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,199 passed · 5 failed (0 new, 5 also fail on main) · 39 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,243 of 2,873 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 (855 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_lazy_resolved_abi_switch_set 35.3 s
Intermittent validation messages (1, seen once in the parallel run, not reproduced when the test was re-run alone 2 times; not counted against this PR)
agc_driver_depth_clear_hle: VUID-vkCmdCopyBuffer-commonparent (6x)
Failing on main too (5, not counted against this PR)
agc_compute_pipeline_inspection
agc_submit_progress
agc_submit_progress_no_timeline
guest_mmap_executable
guest_socket_options_multicast
Passed on retry (1, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)
agc_driver_depth_clear_hle: SEGFAULT in the parallel run; also passed only on retry in 16 other runs in the last 7 days
Validation IDs already present on main (4 IDs in 405 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (405 tests): agc_compute_pipeline_replay, agc_driver, agc_driver_address_passes, agc_driver_address_passes_draw_transitions, agc_driver_address_passes_targets_split, agc_driver_alpha_to_coverage, agc_driver_array_layer_target_cpu, agc_driver_bc_block_copy, and 397 more
VUID-vkCmdCopyImage-srcImage-01548 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-vkCmdCopyImage-srcImage-01551 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (2 tests): agc_driver_prepared_exports, agc_driver_srgb8_color_target
Skipped (39)
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_msaa_dcc_compared_import_2: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_4: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_8: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
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_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_stencil_ref_export: skipped, the device lacks VK_EXT_shader_stencil_export
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_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
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_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_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_fresh: 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_labels: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SD
Reproduce
git fetch origin aa656b2ee52045dade804fd54e33bf693e207ede 52c09d567d2fa453494dd720fcf53a98149468e4
git checkout 52c09d567d2fa453494dd720fcf53a98149468e4 && git merge --no-ff aa656b2ee52045dade804fd54e33bf693e207ede
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.

Re-check — changes requested for current-main integration

The new test exercises the table-callee s_getpc_b64 rewrite, verifies the materialized address and remapped direct branch, and retains rejection of unsupported VCC destinations. I found no new source-level defect in that scoped change.

The reported NVIDIA run is on the PR head merged with main 52c09d5, while current main is aaccd0ba39b7d40fdbf19664575a7e567d8542f7. Current main has since changed GraphBuilder.hpp and GraphBuilder.cpp, which this PR also modifies. The current merge preview is clean, but the old-base GPU/test run does not validate the resulting integration.

Please refresh the branch onto current main, preserve the new table-callee behavior alongside main's GraphBuilder changes, and rerun the focused scalar-call/recompiler tests and the relevant GPU/validation checks on that exact head. The current hosted product jobs are skipped. I did not run these tests locally.

@blawesom

Copy link
Copy Markdown
Contributor

Static review plus an independent Linux/AMD run on both trees per the repo AGENTS shader-recompiler protocol (CachyOS, kernel 7.2.10, GCC 16.2.1, Ninja 1.13.2, Release, BUILD_TESTING=ON, Ryzen 7 9800X3D). No findings.

What I checked

  • The bug and fix shape are right: a table callee checked by UserDataCalleeLength used to throw on any SGetpcB64 ("a linked copy does not keep the PC"), because the callee gets inlined at a different address and its PC read would be wrong. Rather than reject, expandProgramCounterReads rewrites each s_getpc_b64 into s_mov_b32 [reg], lo(addr + pc + 4); s_mov_b32 [reg+1], hi(...) (4 words, the instruction's own post-PCH place), i.e. materializes the original PC as an immediate — semantically identical to what the unwritten-downstream-loading call saw upstream.
  • allowGetpc is scoped exactly where safely done: ReadUserDataCallee(..., true) is applied for table callees only (ReadTableCallees), where the callee's target address is known and constant (callee.target — used as the materialized base). Direct user-data callees (LinkUserDataTail path) are unchanged and still reject SGetpcB64, correctly, since their relinking semantics differ.
  • Who gets materialized values: expandProgramCounterReads is called once per callee entry in LinkCalls, and segments[] sizing/linked.insert(...codes[callee]...) use the expanded form, so the segment bookkeeping and the emitted code agree on the new length. If any expanded code diverges from codes[callee] the segment math would misalign — checked: both go through the same codes vector.
  • Failure modes throw, not silently produce wrong code: non-SGPR-pair destination throws invalid_operand; a direct branch whose target lands outside the (relocated) instruction set throws outside-its-instructions. Bounds (reg + 1 < 106) prevent allocating past the SGPR limit.
  • Test (CheckTableCalleeProgramCounter) pins all three behaviors: default arm still throws on SGetpcB64; allowGetpc path returns the expanded 3-word length and links literal: expected 0xbf820004 / 0xbe9003ff / 0x22334408 / 0xbe9103ff / 0x00000011 / 0xbe80200e (mov pairs for 0x1122334400 + pc + 4 into reg 14) absent the original callee; plain (non-PC) table callees are verified unaffected (unchanged path); a VCC-targeted callee correctly throws into another operand than an SGPR pair. The check then runs BuildCode + TranslateCode on the linked output, so the rewrite survives a full recompile round-trip.

Focused paired test run (VVL env)

tree result
this head aa656b2ee5 1/1 scalar_call Passed (0.02s)
main bb04a4f1ea 1/1 scalar_call Passed (0.02s)

Both logs: 0 was not found but was requested by env var VK_INSTANCE_LAYERS, 0 VUID-. Comparing logs, no new errors introduced by this change.

Not covered

The expansion's address math (address + programCounter + 4) is only validated for the test's single table of one callee at 0x1122334400; multi-callee tables or a callee that reads PC and is the segment-sequence target (relative to the call's relays) aren't explicitly pinned. The segment-length recompute covers it structurally (same codes[callee]), but an end-to-end run that executes such a shader with several PC-reading callees in one table would be higher-signal.
Note on the table: both trees' scalar_call fixture reports 1/1, but the assertion bodies differ at each base (CheckTableCalleeProgramCounter exists only on this PR's head; main runs the pre-PR suite). Head's pass means the new check is active and green at this base; main's pass is the untouched baseline, not the same checks run twice.

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

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head 04bdf18 merged onto main 3741ca9 · tested 2026-11-01 08:22 UTC · 24 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,424 passed · 4 failed (0 new, 3 also fail on main, 1 unstable on main) · 44 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,472 of 3,121 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 (929 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_pipeline_journal 75.6 s, ⚠️ agc_driver_lookup_log_fits_build 73.6 s, ⚠️ agc_driver_graphics_maps_fallback 35.0 s
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)
agc_submit_progress: failed in 6 of the last 10 main runs
Failing on main too (3, not counted against this PR)
agc_driver_image_table
guest_mmap_executable
guest_socket_options_multicast
Validation IDs already present on main (5 IDs in 480 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (480 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 472 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 (44)
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_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_fresh: 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_f
Reproduce
git fetch origin 04bdf1878163552bbab071e2335795c52b8e0b8e 3741ca9327246d0df81638726a986cef862b6db5
git checkout 3741ca9327246d0df81638726a986cef862b6db5 && git merge --no-ff 04bdf1878163552bbab071e2335795c52b8e0b8e
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.

@oneandonlydean
oneandonlydean merged commit 74ca823 into boykopovar:main Nov 1, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* shader core/shader unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants