Repository navigation
perf(shader): keep the vector window to the blocks between relative accesses - #15520
Conversation
✅ NVIDIA GPU test: passedPR head
Unstable on main (2, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Validation IDs already present on main (4 IDs in 517 tests)Skipped (48)ReproduceAutomated 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. |
|
Hi beardsciences, Thanks for this, and for the detailed traces. The region and copy logic look right to me. Two small requests:
|
✅ AMD GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (8, not counted against this PR)Validation IDs already present on main (4 IDs in 518 tests)Skipped (57)ReproduceAutomated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Validation IDs already present on main (4 IDs in 518 tests)Skipped (48)ReproduceAutomated 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. |
✅ AMD GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (9, not counted against this PR)Validation IDs already present on main (4 IDs in 518 tests)Skipped (57)ReproduceAutomated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
Thanks, both done.
CI on a04c37a: TechLevelZero's NVIDIA and AMD runs passed. |
|
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.
|
|
@oneandonlydean both requests from your review are done in the comment above: the entry-prologue variant in a04c37a, and the Dan's Crypt pixel compare. The PR still merges cleanly with current |

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.mainis 4f41f4c, the change is this PR's commit a572e50 on 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
{"commit":"4f41f4c375f5","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"640:60"},"gpu":"NVIDIA GeForce RTX 3060 Ti","driver":"NVIDIA 621.01","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32674,"title_id":"PPSA07550","title":"MediEvil: Resurrection","content_version":"01.000.003","resolution":"3840x2160","window":{"spec":"seconds 640:60","first_present":13995,"ms":60028.524},"presents":1739,"frame_ms":{"p50":31.114,"p90":40.619,"p99":41.598,"max":42.083},"gpu_busy_ms_per_present":6.134,"worker_busy_pct":{"queue worker 0x0":7.300},"top_phases_ms_per_frame":{"VideoOut.Flip":6.491,"VideoOut.Flip.present":6.307,"Driver.Present":6.306,"Driver.Present.render_fence_wait":5.904,"Vulkan.Retire":5.904,"Vulkan.Retire.wait":5.895,"Driver.Packet":2.509,"Graphics.Draw":1.749},"trace_dropped":false,"trace":"aps5-trace-4f41f4c375f5-41496.json.gz"} {"commit":"a572e502064e","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"640:60"},"gpu":"NVIDIA GeForce RTX 3060 Ti","driver":"NVIDIA 621.01","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32674,"title_id":"PPSA07550","title":"MediEvil: Resurrection","content_version":"01.000.003","resolution":"3840x2160","window":{"spec":"seconds 640:60","first_present":18241,"ms":60018.478},"presents":1590,"frame_ms":{"p50":37.942,"p90":42.748,"p99":58.382,"max":71.954},"gpu_busy_ms_per_present":37.330,"worker_busy_pct":{"queue worker 0x0":86.640},"top_phases_ms_per_frame":{"Driver.Packet":32.675,"VideoOut.Flip":32.297,"Driver.Present":32.126,"VideoOut.Flip.present":32.108,"Driver.Present.render_fence_wait":31.464,"Vulkan.Retire":31.464,"Vulkan.Retire.wait":31.453,"Driver.Packet.draw":25.329},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":7.504,"events_lost":1830725,"totals_full":false},"draw committer":{"events_full_after_s":12.089,"events_lost":1021395,"totals_full":false}},"trace":"aps5-trace-a572e502064e-42364.json.gz"} {"commit":"4f41f4c375f5","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"640:60"},"gpu":"NVIDIA GeForce RTX 3060 Ti","driver":"NVIDIA 621.01","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32674,"title_id":"PPSA07550","title":"MediEvil: Resurrection","content_version":"01.000.003","resolution":"3840x2160","window":{"spec":"seconds 640:60","first_present":16452,"ms":60059.768},"presents":597,"frame_ms":{"p50":99.172,"p90":193.318,"p99":216.152,"max":287.487},"gpu_busy_ms_per_present":99.915,"worker_busy_pct":{"queue worker 0x0":90.310},"top_phases_ms_per_frame":{"VideoOut.Flip":99.029,"Driver.Present":98.523,"VideoOut.Flip.present":98.352,"Driver.Present.render_fence_wait":97.692,"Vulkan.Retire":97.692,"Vulkan.Retire.wait":97.678,"Driver.Packet":90.811,"Driver.Packet.rendering_wait":61.132},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":19.348,"events_lost":559515,"totals_full":false},"draw committer":{"events_full_after_s":32.833,"events_lost":215610,"totals_full":false}},"trace":"aps5-trace-4f41f4c375f5-38360.json.gz"} {"commit":"a572e502064e","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"640:60"},"gpu":"NVIDIA GeForce RTX 3060 Ti","driver":"NVIDIA 621.01","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32674,"title_id":"PPSA07550","title":"MediEvil: Resurrection","content_version":"01.000.003","resolution":"3840x2160","window":{"spec":"seconds 640:60","first_present":18227,"ms":60015.649},"presents":1578,"frame_ms":{"p50":38.879,"p90":42.327,"p99":59.463,"max":79.446},"gpu_busy_ms_per_present":37.623,"worker_busy_pct":{"queue worker 0x0":83.734},"top_phases_ms_per_frame":{"VideoOut.Flip":34.866,"Driver.Present":34.688,"VideoOut.Flip.present":34.669,"Driver.Present.render_fence_wait":33.932,"Vulkan.Retire":33.932,"Vulkan.Retire.wait":33.921,"Driver.Packet":31.820,"Driver.Packet.draw":23.122},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":7.508,"events_lost":1822930,"totals_full":false},"draw committer":{"events_full_after_s":12.721,"events_lost":977646,"totals_full":false}},"trace":"aps5-trace-a572e502064e-43468.json.gz"} {"commit":"4f41f4c375f5","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"640:60"},"gpu":"NVIDIA GeForce RTX 3060 Ti","driver":"NVIDIA 621.01","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32674,"title_id":"PPSA07550","title":"MediEvil: Resurrection","content_version":"01.000.003","resolution":"3840x2160","window":{"spec":"seconds 640:60","first_present":16690,"ms":60158.202},"presents":662,"frame_ms":{"p50":89.835,"p90":163.077,"p99":184.732,"max":189.693},"gpu_busy_ms_per_present":90.375,"worker_busy_pct":{"queue worker 0x0":92.326},"top_phases_ms_per_frame":{"VideoOut.Flip":90.028,"Driver.Present":89.502,"VideoOut.Flip.present":89.373,"Driver.Present.render_fence_wait":88.815,"Vulkan.Retire":88.815,"Vulkan.Retire.wait":88.803,"Driver.Packet":83.860,"Driver.Packet.rendering_wait":60.556},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":17.294,"events_lost":636913,"totals_full":false},"draw committer":{"events_full_after_s":31.818,"events_lost":231696,"totals_full":false}},"trace":"aps5-trace-4f41f4c375f5-22248.json.gz"}#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 in a04c37a after 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).
mainis 4f41f4c and the change is this PR's commit a572e50 on 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 at a04c37a),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).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)