perf(shader): keep the vector window to the blocks between relative accesses #15520
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15520"
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 beardsciences on 2026-11-03T17:18:56Z.
What
A program that addresses vector registers relatively (
v_movrels_b32,v_movreld_b32,v_movrelsd_b32,v_movrelsd_2_b32,v_swaprel_b32) keeps its registers from the lowest relatively addressed one up in a window array. When it also writes through the window, every direct access in every block went through that array, even in blocks no relative access can reach or follow.This keeps the window only in the blocks on a path from one relative access to another (the relative blocks plus every block both reachable from one and reaching one). Every other block keeps the registers in SSA values. Execution cannot return into those blocks once it leaves them, so the registers are copied into the window once where control enters them and, for a program with relative writes, back where it leaves. A copy sits at the start of the target block when all of that block's predecessors are on the other side, otherwise at the end of the source block. When the relative blocks are the whole program nothing changes.
APS5_NO_SCOPED_VECTOR_WINDOW=1keeps every block in the window; it is a recompiler switch, so it is part of the shader cache key.The case that showed it: MediEvil: Resurrection (PPSA07550) runs in the PS5's PSP emulator, whose clipping geometry program (3184 words) has all 104 of its relative accesses in a section entered only by a wave with a primitive to clip. With
APS5_PIPELINE_STATS=1on NVIDIA (RTX 3060 Ti), a run from boot to the 3D menu creates 27 pipelines with that program. Onmaineach of their mesh executables has 255 registers, 13,648–14,928 bytes of local memory per thread and 1.57–1.61 MB of code; with this change 255 registers, 3,312–3,744 bytes and 1.24–1.27 MB (Local Memory Sizeless the 2^36 the driver adds to every value; both logs attached). That program draws all of the title's 3D; every PS5 PSP release runs the same emulator.pipeline-stats-main-4f41f4c375.txt
pipeline-stats-pr-a572e50206.txt
Cost in PPSA07550 gameplay: Dan's Crypt, the first level, with Sir Dan standing at the start after the level's opening movie (no input after the menu; presents and GPU time stay flat in 5 s steps across every window in the table). RTX 3060 Ti, warm caches,
APS5_TRACE_SECONDS=640:60and no other trace or profile switch, runs alternating in the ordermain1, change 1,main2, change 2,main3.mainis4f41f4c375, the change is this PR's commita572e50206on it.main, run 2main, run 3Each build first ran once untraced with frame dumps to warm the caches.
main's untraced run never started a new game (its scripted presses did not get it past the menu), so its traced run 1 was the first to build the level's pipelines and was still in the level's opening movie during the window (1739 presents, 6.1 ms GPU busy per present); it is not in the table, but its trace and summary are attached. The four runs in the table reporttrace_dropped(the event buffers of the queue worker and the draw committer filled after 7–33 s);totals_fullis false for every thread, so the summary numbers are complete. Traces andtools/trace_digest.pyoutput attached.aps5-trace-4f41f4c375f5-22248.json.gz
aps5-trace-4f41f4c375f5-38360.json.gz
aps5-trace-4f41f4c375f5-41496.json.gz
aps5-trace-a572e502064e-42364.json.gz
aps5-trace-a572e502064e-43468.json.gz
digest-main-1.txt
digest-main-2.txt
digest-main-3.txt
digest-pr-1.txt
digest-pr-2.txt
summary-main-1.txt
summary-main-2.txt
summary-main-3.txt
summary-pr-1.txt
summary-pr-2.txt
Summary lines, in run order
#15362 (open) stops zeroing the NVIDIA mesh window buffer at workgroup start; it and this PR change different files and merge without a conflict. Neither build above has it.
The change edits the recompiler, so the shader cache's source version changes and cached modules are rebuilt once.
Tests:
agc_vector_windowgains a translation check that registers outside a loop of relative writes stay out of the window (it fails onmain). The new GPU testagc_driver_vector_window_regionruns relative reads and writes inside a loop that only some waves enter, in wave32 and wave64, with a fully active, a partly active and a skipped wave, and covers each copy placement: into the window at the end of a source block and at the start of a target block, back at the start of a target block and at the end of a source block that also leads to a join, and a window that includes the entry block, read relatively at a register only the entry prologue sets (added ina04c37a63cafter review). It also checks inactive lanes, a register only read relatively and a register never written.docs/dev/debt/shader.mddescribes the scoped window and where its copies run.Overlap: 172 open PRs share a file with this one.
tools/pr_overlap.py --branchfinds no overlap with the 98 it could compare; it could not compare the other 74 because they conflict withmain. Checked by hand withgit merge-treeof each againstmainand against this branch: 70 add no conflict with this change, among them #7410, #10359, #11265 and #11490 (they editInstructionTranslator.cpporTranslationContext.hpp) and #12548 (VectorWindow.cpp). #6924, #10757 and #12324 each add anENVIRONMENT.mdrow in the same place as this PR's row, and #14212 rewraps the whole debt file, so whichever of those lands second needs a one-line rebase. #15362 and this PR merge without a conflict.Tested
Windows 11, NVIDIA GeForce RTX 3060 Ti, driver 621.01 (32.0.16.2101).
mainis4f41f4c375and the change is this PR's commita572e50206on it; every build below is a clean tree at one of those two commits, apart from the two local edits named in the second item.tools/check_conventions.py --base origin/mainpasses.Validation,
mainand the change:ctest --test-dir build -R "mesh|vector_window|relative|window_lane|ngg|provoking" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer; both logs attached, each starting with its commit. Neither containswas not found but was requested by env var VK_INSTANCE_LAYERS; the loader insertsVK_LAYER_KHRONOS_validationinto every Vulkan instance (24 inmain's run, 25 in the change's, which has the new test), next to the machine's implicit layers (NVIDIA's and the OBS and Overwolf capture hooks). The layer reports the same 20 messages in both, allWARNING-VkImageSubresourceRange-layerCount-compatibility, and noVUID-error.mainpasses 28 of 28, the change 29 of 29.validation-main-4f41f4c375.txt
validation-pr-a572e50206.txt
agc_driver_vector_window_regionfails when any copy placement is removed from the translator (local edits, not in this PR): without the copies at the start of a target block,loop, wave32 lane 0 v10 is 0x00000002, expected 0x00000001; without the copies at the end of a source block,v1 is 0x00000000, expected 0x00000001; without the copy into the window after the entry prologue (entryIr.SyncVectorWindow(true), checked ata04c37a63c),entry block reads an input register, wave32 lane 1 v1 is 0xdeadbeef, expected 0x00000011. The newagc_vector_windowcheck fails withAPS5_NO_SCOPED_VECTOR_WINDOW=1.agc_driver_mesh_vector_window_wavespasses with this change (2 of 2) and still fails withAPS5_NO_MESH_WINDOW_BUFFER=1(2 of 2, wrong threads per wave: 0 64 64 64); log attached.regression-pr-a572e50206.txt
python tools/select_tests.py ctest build --output-on-failure --timeout 120 --parallel 4on the change: 3907 of 3919 pass. Six of the twelve failures pass when run alone. The other six:test_registrationandselect_tests_MissingCommandTestsneed symlink rights (os.symlink, WinError 1314),annotate_moduleandconventions_wrapped_declarationstime out, andagc_driver_direct_write_completionandagc_driver_store_over_untrackedfail the same way onmainand withAPS5_NO_SCOPED_VECTOR_WINDOW=1(neither has relative addressing).MediEvil: Resurrection (PPSA07550), both builds from boot through the 3D main menu, the New Game movie and Dan's Crypt: the menu and the level render the same.
Before:

main, the spot the traces measure (frames from separate runs of the same builds withAPS5_DUMP_FRAMES).After: this PR, the same spot.

Pixel compare of these two frames: 5,911 of 518,400 pixels differ (1.14 %), 49 of them by more than 24 of 255, all on Sir Dan's idle pose, the flickering light in the doorway and a few dust pixels; the rest is identical bit for bit. The closest pair of frames within one build differs more:

main1.95 %, this PR 1.55 %. Red marks every pixel that differs.3D main menu,


mainand then this PR (the skeleton's idle pose differs between the two frames).Not tested here: AMD and Intel GPUs (the change applies on every GPU), other NVIDIA GPUs and drivers. TechLevelZero's CI passed on
a572e50206anda04c37a63con an NVIDIA RTX 2000 Ada (Linux, 595.99.02) and an AMD Radeon RX 6300 (RADV, Mesa 25.2.8).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)