Skip to content

perf(agc): bound vertex-indexed guest buffers by the draw's vertex range - #8

Closed
savvaniss wants to merge 1 commit into
Get-fix:ps4/limbo-gpufrom
savvaniss:perf/ps4-gcn-vertex-ring-extent
Closed

savvaniss wants to merge 1 commit into
Get-fix:ps4/limbo-gpufrom
savvaniss:perf/ps4-gcn-vertex-ring-extent

Conversation

@savvaniss

Copy link
Copy Markdown

What

A PS4 vertex shader reads its vertices through a fetch subroutine that it calls with s_swappc. On boykopovar#6977's branch the driver links that subroutine into the program (LinkUserDataCallees), so its loads stay ordinary guest-buffer loads indexed by v0, not vertex attributes. Their V#s describe the title's whole vertex ring, so each draw binds the ring whole. When the draw cache reuses a draw at a moved base, PrepareDrawBindings snapshots the ring whole as well. In Monopoly Plus that is 0x27ffff0 bytes per draw, about 870 times per frame.

This PR bounds such buffers by the draw's vertex range, as lifted vertex attributes already are (VertexBufferReadSize):

  • The resource tracker proves, for each buffer resource, that every access is an IDXEN load whose index is the VertexIndex builtin and whose VGPR offset and SOFFSET are immediates. It records how far past index * stride the loads read, with 16 bytes for a formatted load. The value reaches the driver as DescriptorBinding::bufferVertexExtent (shader disk cache format 37).
  • For a direct draw on the vertex path with no mesh or tessellation stage, a read-only element with that proof is bound and alias-checked only up to maxIndex * stride + extent. The same limit applies when its V# moves and it is snapshotted. The size is rounded up to 16 bytes and never exceeds the V#'s own size. maxIndex is the one the vertex attributes already use: the highest index plus the base vertex, or the last vertex of an auto draw.
  • A draw recipe whose template was bound for another vertex range is a miss (DrawRecipeMiss::VertexRange), and the draw then takes the template-hit path.
  • Everything unproven keeps today's whole range: indirect draws, mesh, tessellation and geometry paths, written elements, swizzled or ADD_TID V#s, and any element with another kind of access.

Nothing in it depends on the title. The proof also applies to PS5 vertex shaders that read a buffer by v5.

Tested

Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, on boykopovar#6977's head 93eeee014.

  • agc_shader_vertex_index_extents (new) compiles RDNA (index v5) and GCN (index v0) vertex shaders and checks the extent reported for each:

    • buffer_load_format_xyzw by the vertex index: 16.
    • buffer_load_dwordx2 at offset 8 with SOFFSET 4: 20.
    • A load by the vertex index plus one: 0.
    • A V# read both ways: 0.

    With the tracker change reverted it fails with "vertex extent 0, expected 16".

  • agc_driver_vertex_range_bindings (new, mock device) checks the bound size and that each unproven case keeps the whole V#. It builds ShaderResources with and without a vertex range. It moves the V# by one quad through MovedReadOnlyBuffers and PrepareDrawBindings and checks the snapshot's size and bytes, and it checks BindsVertexRange. With the driver cut reverted it fails with "a read-only element indexed by the vertex index was not cut to the draw's last vertex".

  • agc_driver_vertex_indexed_ring (new, Vulkan) runs an RDNA vertex shader that reads a 64 KiB ring by the vertex index and stores what it read. It checks every value for auto draws from vertex 0 and from vertex 5, and for an indexed draw with base vertex 20. It passes on both GPUs. With the bound made one fetch short it fails with "vertex 7 component 0 is 0", so it exercises the bound on the GPU. A GCN variant is not included: GCN V#s carry 40-bit addresses, and the test's arrays sit above 2^40 on Windows.

  • agc_shader_disk_cache passes.

  • Validation layer: 28 focused tests on 93eeee014, and the same 28 plus the three new ones on this branch, on both GPUs, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. The tests cover draw cache reuse and relocation, draw snapshots, vertex fetch, rect lists, offset indices and write ranges. All pass.

    • Both sides log the same one VUID-vkDestroyDevice-device-05137, from the unchanged agc_driver_vertex_target_range_copied, on each GPU.
    • Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS, and each log's Selected GPU line names the GPU of its run.
  • agc_driver_gpu_indirect_arguments_misaligned_writer_ahead_tests does not compile with MinGW on either side ("requested alignment '65536' exceeds object file maximum 8192"). That is unrelated to this change.

  • tools/check_conventions.py --base 93eeee014 passes.

  • tools/pr_overlap.py reports only fix(agc): PS4 display, textures and GCN instructions for CUSA03312 #1, on the two adjacent static_assert lines of ShaderDiskCache.cpp. They compose: BufferResource 13 from here and ImageResource 39 from fix(agc): PS4 display, textures and GCN instructions for CUSA03312 #1.

Monopoly Plus (CUSA03312), RX 9070 XT, APS5_RESIDENT_LINEAR=1, on the local PS4 stack the title needs to start: boykopovar#6977's head with #1, #2 and #5 and local stand-ins. Base is that stack. Change is the same stack with this commit cherry-picked. The stack carries the closed boykopovar#8243, and the conflicts were resolved by applying both cuts. Base and change runs alternated.

  • APS5_LOG_BIG_SNAPSHOTS=1: base logs 400 new draw snapshots of +0x27ffff0 (the log stops at 400). The change logs none.

  • APS5_TRACE_SUMMARY_EVERY=15 over the whole run:

    • Base runs the starting screen at about 11.4 fps for its first ~95 s, then the language screen at 2.8 to 3.0 fps.
    • The change runs the starting screen at about 59 fps and reaches the language screen within 30 s.
  • On the language screen (one 240:15 and two 120:15 windows each):

    build fps frame p50 device_lock ms/frame capture_resources ms/frame
    base 2.79, 2.86, 2.91 339 to 348 ms 151 to 163 115 to 117
    change 6.01, 6.14, 6.16 161 to 167 ms not in the top eight 111 to 114

    What remains on that screen is the per-draw resource capture (Shader.DrawStage.capture_resources). This PR does not address it.

  • Summary lines of the 240:15 windows on the language screen:

    • Base: {"commit":"02fc0a86a4fe","dirty":true,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_RESIDENT_LINEAR":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"240:15","APS5_TRACE_SUMMARY_EVERY":"15"},"gpu":"AMD Radeon RX 9070 XT","driver":"AMD proprietary driver 26.8.1 (LLPC)","os":"Windows 10.0.26300","resolution":"1920x1080","presents":42,"frame_ms":{"p50":339.4,"p90":433.2,"p99":520.4},"gpu_busy_ms_per_present":98.1,"top_phases_ms_per_frame":{"Driver.Packet":357.2,"Driver.Packet.draw":201.7,"Driver.Packet.device_lock":150.6,"Driver.Draw.shader_compile_and_link":148.1,"Shader.DrawStage.capture_resources":117.1}}. Base is dirty because that prx was built with the experiment's extent logging uncommitted.
    • Change: {"commit":"9c5c8619f7ab","dirty":false,"env":{...same...},"gpu":"AMD Radeon RX 9070 XT","driver":"AMD proprietary driver 26.8.1 (LLPC)","presents":91,"frame_ms":{"p50":166.6,"p90":168.6,"p99":170.6},"gpu_busy_ms_per_present":97.4,"top_phases_ms_per_frame":{"Driver.Packet":164.7,"Driver.Packet.draw":153.0,"Driver.Draw.shader_compile_and_link":143.7,"Shader.DrawStage.capture_resources":113.6},"trace_dropped":true}. The worker's slice buffer filled after 8.4 s, but its totals are complete (totals_full false).
  • tools/trace_digest.py of the same two traces:

    • Base: worker busy 352.6 ms per frame (98 %), GPU 97.8. Largest slices: Driver.Packet 352.8, Driver.Packet.draw 201.6, Driver.Packet.device_lock 149.7, Driver.Draw.shader_compile_and_link 146.5.
    • Change: GPU 97.2 ms per frame, Driver.Packet 89.5 in the slices kept, and no device_lock among the largest slices.
    • The traces are not attached. They stay on the test machine and can be shared.

Checklist

🤖 Generated with Claude Code

A GCN vertex shader reaches its fetch subroutine through s_swappc. The
driver links that subroutine into the program, so its buffer loads stay
generic guest-buffer loads indexed by v0 rather than lifted vertex
attributes. Their V#s describe the whole vertex ring, so every draw bound
and, when the draw cache reused a draw at a moved base, snapshotted the
ring whole.

The resource tracker now proves, per buffer resource, that every access
is an IDXEN load whose index is the VertexIndex builtin and whose VGPR
offset and SOFFSET are immediates, and records how far past
index * stride those loads read (formatted loads count 16 bytes). The
value reaches the driver as DescriptorBinding::bufferVertexExtent (shader
disk cache format 37).

For a direct draw on the vertex path without mesh or tessellation
stages, a read-only element with that proof is bound, alias-checked and
snapshotted when its V# moves only up to maxIndex * stride plus the
extent, rounded up to 16 bytes and never past the V#'s own size. maxIndex
is the bound vertex attributes already use: the highest index plus the
base vertex, or the last vertex of an auto draw. A recipe hit whose
template was bound for another vertex range is a miss. Indirect draws,
written elements, swizzled or ADD_TID V#s and any other access keep the
whole range.

Monopoly Plus (CUSA03312) draws its quads from a 40 MB ring whose base
advances 0x60 bytes per draw. Its 0x27ffff0-byte draw snapshots are gone,
and its language screen runs at about 6.1 instead of 2.9 frames per
second on an RX 9070 XT.

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

Get-fix commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Thanks @savvaniss. boykopovar#6977 is now a draft integration branch, and its own work is split into boykopovar#9429 to boykopovar#9433 (details). The maintainers asked that the branch not land anything without its own review, so could you open this upstream against main, straight on main if it needs nothing from the PS4 parts (you noted the path is the same there), otherwise on top of boykopovar#9431, with Depends on? Once it's open, I'll merge it into ps4/limbo-gpu, list it as a member and run Limbo with it. ps4/limbo-gpu now moves to the split branches, so this pull request may show conflicts here.

AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

@savvaniss

Copy link
Copy Markdown
Author

Moved upstream as boykopovar#9897, straight on main. Closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants