fix(recompiler): read lane spills back through relative-addressing window registers #6277
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6277"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-15T08:54:34Z.
What
A program with any
v_movrels/v_movreldkeeps its relative-addressing window in array storage (#3856), so av_writelanespill into a window register reaches itsv_readlaneasReadLane(LoadVectorWindow k), andReadLaneEliminatorstopped there. A descriptor spilled that way stays a run-time value, and resource analysis rejects it. In PPSA08427 (Killing Floor 3) that skips about 750 draws per 10 s withGetSamplerResource dword 0 is not a valid runtime value, and large UE5 compute programs fail withGetImageResource dword 0 is not a valid runtime value.WriteLanechain down to a window load, whose lane is the flow's value at that load, so the chain continues across window registers.v_readlanestays as before, when predecessors disagree, a store's lane is not a lane write, or the flow does not settle within a bound.Tested
CachyOS Linux (kernel 7.2.9), NVIDIA GeForce RTX 3060, driver 615.78.08, GCC 16.2.1, Release, on
main721db55dc.agc_driver_window_lane_spill: an output V# spilled withv_writelaneinto a window register (the window starts below it) and read back withv_readlanebefore a buffer store; then the same with a secondv_movreldwith a computed index between the spill and its read-back. Onmainit fails:lane 0 stored 3735928559 through the V# read back from a window register.agc_driver_window_lane_spill,agc_vector_window,agc_driver_vector_window_direct_access,agc_driver_relative_indexing,agc_driver_scalar_relative_indexing,agc_driver_write_lane,agc_shader_memory.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01Uzy15wqYTt6iWyxYXEzUWo
Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-15T12:44:35Z.
Death Stranding 2 (PPSA02015) stops on this. On a local stack (current main plus what it needs to get that far, including PR 5426, PR 5855 and PR 6297), compute shader 0x8280575600 throws at about 150 s:
GetImageResource dword 0 is not a valid runtime value; chain: LoadAddressU32@pc=0x000010dc(GetAddressResource(ReadLane(LoadVectorWindow(Immediate), ...With this PR cherry-picked on top, the shader compiles and the title runs on to 184 s, where it stops on a storage image access to a multisampled color target that is unrelated to this change.
agc_driver_read_laneandagc_driver_window_lane_spillpass here on an RTX 5080 and on a Radeon 610M (RADV), with the PR merged onto current main; lavapipe skips both.Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T13:06:46Z.
Resident Evil 4 (PPSA07411) stops on this pattern too, in a mesh program, but this PR does not get it past. Windows Server 2025, RTX 3060, driver 591.86, MinGW GCC 15.2, Release.
On a private build of
main8cd937e29+ #6126 + #5884 (the stops before this one), the title ends on its resource loader thread, insceAgcCreatePrimState->Driver::ResolveGraphicsStagesAbi->PrepareGraphicsStages:I cherry-picked
fe6d2d2e9onto that build and replayed the saved request withagc_shader_replay --prepare: it fails with the same message. With therejectedslots kept as candidates incollectLaneSpillSlots(a local experiment), it prepares (1,558,931 SPIR-V words).The reason is the rule that a spill slot is only ever lane-written and lane-read. The window starts at
v5, and the spill register isv16, slot 11. In the first part of the program, before any relative access,v16is an ordinary register: vector ALU instructions write it and read it. Later the program reuses it for SGPR spills. Current LLVM allocates the spill VGPRs like other registers, so one register can be ordinary in one part of a program and hold spill lanes in another. Slot 11 therefore has ordinary stores and loads,collectLaneSpillSlotsrejects it, and the computed-index stores between the spill and the read make the lane unknown. The index can't be bounded statically either: it is computed from per-lane data, and the window runs pastv16, so M0 = 11 is not excluded.What we ran for this title instead (not opened as a PR, since this one implements the same function): a constant-slot
LoadVectorWindowwalks the control flow back to the constant-slot stores that reach it, and computed-index stores on the way are taken not to reach the slot. It is the same assumption as yours (the compiler does not index into a register while a spill lives in it), applied while the spilled lane is live instead of per slot. With it the program prepares, and the title goes on past this stop: with the later fixes it reached the brightness calibration screen (1,485 s run) and the play-data consent screen (2,096 s run), with no driver failure.Suggestions:
Keep a known lane across computed-index stores. In
laneFlowa lane only becomes known throughv_writelane, so a known lane is a live spill at that point. That is when the assumption applies, and the program-widerejectedrule would no longer be needed. This PR would then cover PPSA07411 too.Record the assumption in technical debt (
docs/dev/debt/shader.md, next to "Relative vector addressing"). Here is the entry I used, if it helps:If you'd rather not rely on the assumption at all: the computed-index stores that the flow skips could record a fault in the fault buffer (as
UnlinkedCalldoes) when their index is the slot and the invocation is the spilled lane. The host then throws instead of the shader reading a stale value. I can send that as a follow-up once this lands.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T16:30:13Z.
Review: COMMENTED
Tested on Apple as another vendor; the new regression reproduces and the fix clears it.
The window-lane spill path runs on Apple silicon (subgroup size 32, so
agc_driver_window_lane_spillis not skipped).agc_driver_window_lane_spillpasses.ReadLaneEliminatorchange: it fails withAGC graphics: window lane spill: lane 0 stored 3735928559 through the V# read back from a window register,so the test does guard the regression here.
^agcsuite: 13 failures, same set as the base (all pre-existing on MoltenVK: denormals/rounding, dpp16, pixel interlock, relative ancillary, etc.). No new failures from this PR.Method: macos-port @ b7eb6b6b + ImportWatched + PR diff, not main. Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta, driver SDK MoltenVK 1.4.2.
GPUs tested: Apple M2 Max (MoltenVK 1.4.2).
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-16T12:12:34Z.
@hypermoist I tested head
fe6d2d2e9cherry-picked onto maind92a8dad3with LEGO Horizon Adventures (PPSA14632, 01.004.000). The six focused tests (shader memory, vector window, relative indexing, scalar relative indexing, window lane spill, write lane) pass, but all four captured LEGO compute requests still fail with:This appears to match the reused-register limitation described above: the first sampler reads resolve, but later reads do not. Keeping every constant slot as a spill candidate makes all four compile in a diagnostic experiment; I reverted that experiment and have not claimed gameplay success.
I also made a small synthetic counterexample for the computed-store assumption. It keeps the output buffer descriptor intact, spills
0x1234into lane 0 of v3, then executesv_movreld_b32 v2, v0before reading v3 lane 0:0x1234, and passes.0, but this PR outputs4660(0x1234).The same two cases pass when rebuilding the test/driver with only ReadLaneEliminator.cpp restored to its main implementation. This is a host GPU execution comparison, not a console hardware-oracle result.
The patch below applies to this PR's WindowLaneSpill.cpp. Build
agc_driver_window_lane_spill_testsand run it with--indexed-alias-onlyto isolate the counterexample. No game code or shader captures are included.Synthetic regression test patch
Tested on Windows 11, NVIDIA RTX 5070 Ti (driver 32.0.16.1692), MinGW GCC 15.2, Release. AI-assisted: yes (Codex). I am investigating guarded spill tracking locally; the proposed fault-buffer check above looks relevant for avoiding silently stale values.
Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-17T21:58:12Z.
Tested on God of War Ragnarök (PPSA08330, 06.006.000), Windows 11, RTX 3080 10 GB (NVIDIA 610.74), WinLibs GCC 15.2. Base: our test branch (main
82f0c9aec+ #6946 + #6958 + #7238 + #7223 + a few open picks).GetSamplerResource dword 0 is not a valid runtime value; chain: ReadLane(LoadVectorWindow(Immediate)....GetSamplerResourcestop, which is a different chain (LoadAddressU32(GetAddressResource(Phi(Phi(ReadConstBuffer…, #6191).LLM assistance used (Claude); runs on our machine.
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-20T18:47:58Z.
@fdfawef324 your first suggestion here didn't make it into this PR before it merged: keep a known lane across computed-index window stores, since in
laneFlowa known lane is a live spill.mainstill stops on that pattern, in RE4's mesh program and in @THEMANnt's four LEGO Horizon Adventures requests (#6952).Are you planning to open it yourself? If you'd rather not, I'd like to open it in a few hours with you as co-author: your
laneFlowchange and debt entry, plus a GPU case inagc_driver_window_lane_spillthat fails onmain(a window slot written as an ordinary register before the spill). THEMANnt, the same goes for your prototype if it differs. I'll hold off on opening until you've had a chance to answer.Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-21T04:16:28Z.
@fdfawef324 I've opened it as #8881, with you as co-author: your
laneFlowsuggestion and debt text, plusagc_vector_windowandagc_driver_window_lane_spillcases that fail onmainwith LEGO Horizon Adventures' message. If you'd rather carry it yourself, or your RE4 variant differs in a way that matters, say so and I'll close mine. @THEMANnt, a run of the LEGO requests with it would be very welcome.