perf(recompiler): keep relatively addressed vector registers in a window array #3856
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3856"
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 ErenYeager1836 on 2026-10-11T18:00:52Z.
What
Carrying @Mouad-Scriptz-0's fix from #3842 (commit
f8ed012e).v_movrels_b32,v_movreld_b32,v_movrelsd_b32,v_movrelsd_2_b32andv_swaprel_b32lowered to a compare-and-select chain over every register from the base to the program's last allocated register, so a program addressing 154 registers 104 times turned 3176 ISA words into 649,515 SPIR-V words that Intel's compiler did not finish. The registers from the lowest relative base up now live in a function-scope array per invocation (LoadVectorWindow/StoreVectorWindow), so an indexed access is one load or store; plain accesses to those registers go through the same array, DPP-modified relative writes keep theirDppUpdateU32merge, an index past the window reads 0 and drops its write, and programs without relative addressing are unchanged. The same program recompiles to 392,333 words with 4,992 selects instead of 32,383.Fixes #3842.
Tested
python tools/check_conventions.py --base origin/mainpasses.main(a11c8f7f7).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-11T18:04:11Z.
Linux results for this commit, from #3842:
agc_vector_window,agc_driver_relative_indexing,agc_driver_scalar_relative_indexingandagc_driver_dpp16_operandspass on Fedora 44 / Intel Arc Meteor Lake (Mesa 26.2.3);ctest -j4 --timeout 180on a tree carrying this with #3622, #3534 and two further local AGC fixes, without the sevenagc_driver_*tests that fail the same way on a cleanmainbuild on this iGPU: 821 passed, 5 skipped, 1 failed (agc_driver_emulated_color_compare, an ANV sRGB sampling limit that fails identically on cleanmain). Killzone: Liberation (PPSA11142) goes from freezing on its first PSP frame to playing its logos and reaching its language menu at 30 fps; a new pipeline variant of that program compiles in about 20 s withAPS5_NO_PIPELINE_LTO=1. Thanks for carrying it.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T18:15:31Z.
Review: CHANGES_REQUESTED
Thanks for carrying this, and thanks @Mouad-Scriptz-0 for the Arc and Killzone runs. The window array itself looks good: a build and the scoped ctest pass here (405 tests), including
agc_vector_window,agc_driver_relative_indexing,agc_driver_scalar_relative_indexingandagc_driver_dpp16_operands. The problem is the out-of-range behaviour the PR adds. We measured it on RDNA2 hardware (gfx1035, 40 VGPRs allocated, a differentv0in every lane), and it doesn't match what the PR does:v0, not 0. "Out of range" means base + M0 ≥ the VGPR allocation, and the write is dropped. For example, withv_movrels_b32 v10, v32, any M0 ≥ 8 readsv0. The PR reads 0 (ControlFlowInstructions.cpp:318,Select(inRange, loaded, 0)). So the TechnicalDebt line ("reads 0 ... as the RDNA ISA describes") is wrong.v0is read and nothing is written. The PR computesraw = (reg - windowBase) + M0in 32 bits (:307). When the base register is above the window start, M0 = -1 wraps back into the window, so the PR reads or writes the register below the base.v_swaprel_b32with either side out of range writes nothing, to the destination or to the source. The PR still writes the value it read out of range into the in-range side.v_movrelsd_b32/_2with only the source out of range readsv0and does write an in-range destination.To check this against the PR's own code, we appended these rows to
tests/execution/RelativeIndexing.cpp(window v30..v37, lane value x = 0x1000·(lane+1)). The HW and PR columns are for lane 0, and the pattern is the same for every lane:s_mov_b32 m0, -1/v_movrels_b32 v21, v32→ v21v0(= lane id, 0x0)v_movreld_b32 v33, v4→ then v32v_movrelsd_b32 v35, v34→ then v34s_mov_b32 m0, 0x103ff/v_swaprel_b32 v31, v32→ v32maindoesn't get these right either: its select chain falls back to the base register. But this PR replaces that with another model and documents it as the ISA's. What would fix it:relativeWindowAccess, check the range on M0 itself:offset < windowSize - (reg - windowBase), unsigned. The clamped index can stay as it is.v0when the index is out of range (GetVectorReg(0), which goes through the window when v0 is in it). Onlyv_swaprel_b32writes, and only when both sides are in range.OpConstantNullinitializer on theOpVariable). An unwritten register currently reads an undefined SPIR-V value; onmainthe SSA builder gives it 0.RelativeIndexing.cpp, plus a row where the source is out of range and the destination is in range (v_movrelsd_2_b32with M0 = 0x000103ff: the destination getsv0). Add the same rows to a wave64 test as well, since the window is one array per lane half.VectorWindow.cpponly counts IR shapes, so it can stay as a regression guard for the select count, but the behaviour needs value rows.v0and writes are dropped, measured on gfx1035. Say that the window ends at the last register the program names rather than at the shader's VGPR allocation, which the recompiler doesn't know. So a relative write past the named registers but inside the allocation is dropped, while hardware keeps it and a later relative read would see it. Also give the actual size (649,515 → 392,333 words) instead of "noted in its pull request".RelativeWindowAccess(ControlFlowInstructions.cpp:296-297). It describes the select chain this PR replaces, and CONVENTIONS asks for no comments in code.Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-11T18:37:45Z.
Thanks for the measurements. Fixed on
feat/recompiler-vector-windowinf9fd0f12(already in this PR) and876c4eca, for @ErenYeager1836 to add:relativeWindowAccesschecksoffset < windowSize - (reg - windowBase)on M0 itself, unsigned; the clamped index is unchanged.v0(GetVectorReg(0), through the window when v0 is in it); writes are dropped, andv_swaprel_b32writes neither side unless both are in range (writeRelativeVectortakes an enable; the swap passes the conjunction of both ranges).OpVariablehas anOpConstantNullinitializer; two new rows read a never-written window register directly and throughv_movrels_b32and expect 0.RelativeIndexing.cppruns the program in wave32 with 32 lanes and wave64 with 64 lanes, computes the expectations per lane, and pins your rows (movrelswith M0 = -1 readsv0;movreld/movrelsdwith M0 = -1 leave v32, v34 and v33;swaprelwith M0 = 0x103ff leaves v32;movrelsd_2with M0 = 0x103ff gives the destinationv0). The wave64 run found one more defect:LoadVectorWindowwas not aLaneSourceinSpirvAnalysis, so a wave64 program's second half reused the first half's load; it is one now.VectorWindow.cppstays as the IR-shape guard.agc_driver_relative_indexing), that an unwritten window register reads 0 where the console's value is undefined, the window ending at the last named register with the dropped-write consequence, and the sizes.Tested on Fedora 44 / Intel Arc Meteor Lake (Mesa 26.2.3), all three commits:
agc_driver_relative_indexing(wave32 and wave64, 19 rows),agc_driver_scalar_relative_indexing,agc_driver_dpp16_operandsandagc_vector_windowpass; fullctest -j4 --timeout 180without the sevenagc_driver_*tests that fail on a cleanmainbuild on this iGPU: 827 tests, 1 failed (agc_driver_emulated_color_compare, an ANV sRGB sampling limit that fails identically on cleanmain);tools/check_conventions.py --base origin/mainandgit diff --checkpass. I cannot run the hardware oracle here (no AMD GPU), so your rows are the measurements.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by ErenYeager1836 on 2026-10-11T18:38:11Z.
Updated with @Mouad-Scriptz-0's commit addressing the review: M0 is unsigned, out-of-range reads return v0, v_swaprel drops writes when either side is out of range, the window array is zero-initialized, and the gfx1035 test rows and TechnicalDebt updates are added. Conventions check passes.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T22:10:55Z.
Review: APPROVED
Checked the measured out-of-range semantics (unsigned M0, out-of-range read returns
v0, writes dropped,v_swaprel_b32writes neither side unless both are in range, zero-initialised window),agc_vector_windowandagc_driver_relative_indexing(wave32 and wave64) on the PR merged onto main, and that both fail without the change. Thanks @Mouad-Scriptz-0 for the Arc/Killzone runs. Merging once CI is green.