Skip to content

perf(agc): read recorded store bytes in captures instead of waiting for the GPU - #10

Closed
savvaniss wants to merge 2 commits into
Get-fix:ps4/limbo-gpufrom
savvaniss:perf/ps4-ce-dump-stored-values
Closed

savvaniss wants to merge 2 commits into
Get-fix:ps4/limbo-gpufrom
savvaniss:perf/ps4-ce-dump-stored-values

Conversation

@savvaniss

@savvaniss savvaniss commented Oct 20, 2026 •

Copy link
Copy Markdown

What

A PS4 title that uses the constant engine builds its descriptor tables in constant RAM and dumps them to memory with DUMP_CONST_RAM before each draw. While GPU work is open, preparePacketMemory resolves such a store (Pm4::ResolveStore, up to 64 KiB, also COPY_DATA and DMA_DATA) and VulkanDevice::WriteLabelOnGpu records it into the batch as a vkCmdUpdateBuffer into the host import. The range is then a pending write. The next draw's resource capture reads the dumped table through the flush hook, which submits the batch and waits for the GPU, although the driver already holds the bytes it stored.

This PR lets a capture read those bytes instead of waiting:

  • The recorder's label table kept values only for stores up to LabelTableBytes (64). Wider stores were ranges only (wideLabels). They now keep their bytes and a record sequence too. markOverwritten flags them like table entries when later GPU work writes over them, and they leave with their batch as before.
  • Recorder::LookupStoredBytes composes a dword-aligned range from the newest recorded store of each dword. A table entry wins over wide stores, since a wide store erases the table entries it covers when it is noted. The lookup refuses a dword with no store, one a later GPU write covers, a label behind a completion action and any range under a queued label.
  • Driver::classifyPendingWrite answers KnownValue with those bytes when the caller passes a buffer for them. Callers that do are the capture's word reads (ShaderMemory), captureStable and validateCaptured. Callers that pass none, and every other pending write, sync as before. The store lands after everything recorded before it and before everything recorded after it, so its bytes are what the next draw reads on the GPU. An earlier CPU store to the range is overwritten by it there as well.
  • APS5_NO_STORED_KNOWN_VALUES=1 turns the path off. With APS5_VERIFY_KNOWN_VALUES=1 each served word is also read through the hook and compared. The [capture] profile line now reports those counts; before this they only reached the [copy] line, which a title without copy kernels never prints.

Nothing depends on the title: any resolved store, label or constant RAM dump that a capture reads is served the same way.

Tested

Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, on boykopovar#6977's head 93eeee014 with #8, which this branch stacks on.

  • agc_driver_dumped_constant_capture (new, Vulkan, driver end to end) submits one DCB:

    • a draw whose pixel shader reads a constant through its user words;
    • a 128 KiB DMA_DATA fill, so a batch is open (in this harness each draw runs as its own synced batch);
    • WRITE_CONST_RAM of 36 words and a 144-byte DUMP_CONST_RAM into guest memory;
    • the same draw reading the dumped constant 1.0.

    It checks that the dump landed, that the draw wrote 255 and that the capture was served from the recorded store. It skips when the dump was not recorded on the GPU. It passes on the RX 9070 XT, also with APS5_VERIFY_KNOWN_VALUES=1. With the path off (APS5_NO_STORED_KNOWN_VALUES=1, today's behaviour) it fails with "the capture of the draw after a constant RAM dump recorded on the GPU waited for the GPU instead of reading the dumped words".

  • agc_recorder_stored_bytes (new, agc_driver_recorder_tests --stored-bytes-only) checks:

    • a 144-byte store served whole and in part, and refused past its end or off dword alignment;
    • two overlapping wide stores composed newest first;
    • a label inside a wide store winning, and a later wide store erasing it;
    • a queued label refusing the range until forgotten;
    • a non-label write refusing only the stores it covers;
    • entries leaving with their batch.
  • Validation layer: 28 focused tests on the base and the same 28 plus the two new ones here, on the RX 9070 XT (ANYPS5_GPU=AMD), with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. They cover recorder stores, pending writes, key stores, unit shadows, draw cache reuse and relocation, label order and waits, gated dispatch capture, store results and vertex ranges. All pass.

    • Per test, both sides log the same VUIDs. The base has them all already: VUID-vkCmdPipelineBarrier-srcAccessMask-02815 (agc_unit_shadow, agc_shadowed_key_stores), VUID-vkBeginCommandBuffer-commandBuffer-00050 (agc_driver_partially_resident_pending_stores) and VUID-vkDestroyDevice-device-05137 (agc_driver_vertex_target_range_copied).
    • Every device the tests opened was the RX 9070 XT: the recorder fixture's Vulkan device lines and the driver's Physical device selected lines.
    • No log contains was not found but was requested by env var VK_INSTANCE_LAYERS.
  • 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 ShaderDiskCache.cpp lines of perf(agc): bound vertex-indexed guest buffers by the draw's vertex range #8's commit.

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, #5 and #8, plus local stand-ins. Base is that stack, and change is the same stack with this commit cherry-picked.

  • Profile of the base (APS5_PROFILE_DRAW=1) on the language screen:

    • About 3,000 captures per 10 s read a dword under a pending write. Each waited about 2.2 ms in the hook, 6.7 s of GPU waits per 10 s.
    • [hooksync] charges every one of those waits to the capture read site.
    • The title issues about 3,000 DUMP_CONST_RAM per 10 s, of 144, 256 or 512 bytes.
  • APS5_VERIFY_KNOWN_VALUES=1 with the change: 22,709 words served from recorded stores in 80 s, 22,709 verified, 0 mismatches. Capture waits fell to 11 words.

  • Alternating runs, APS5_TRACE_SUMMARY_EVERY=15 with a 120:15 window. Both builds sit on the language screen from about 30 s.

    build fps frame p50 GPU busy ms/present shader_compile_and_link ms/frame capture_resources ms/frame device_lock ms/frame
    base 6.08, 6.06, 6.07 163.6 to 164.5 ms 97.6 to 97.8 142.3 to 142.4 112.0 to 112.9 not in the top eight
    change 8.33, 8.23, 8.36 119.1 to 121.5 ms 89.6 to 91.0 35.5 to 37.1 not in the top eight 67.7 to 69.2

    The worker now waits about 69 ms per frame for the device lock while about 90 ms of GPU work runs per frame. That is the next cost on this screen, and this PR does not address it.

  • Summary lines of the first pair:

    • Base: {"commit":"9c5c8619f7ab","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_RESIDENT_LINEAR":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"120: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":92,"frame_ms":{"p50":163.553,"p90":169.755,"p99":179.944},"gpu_busy_ms_per_present":97.573,"top_phases_ms_per_frame":{"Driver.Packet":162.891,"Driver.Packet.draw":151.459,"Driver.Draw":151.119,"Driver.Draw.shader_compile_and_link":142.416,"Shader.DrawStage":140.547,"Shader.DrawStage.capture_resources":112.045,"Shader.DrawStage.prepared_invocation":17.515,"Shader.DrawStage.materialize":10.915}}
    • Change: {"commit":"2c09e4328dc6","dirty":false,"env":{...same...},"gpu":"AMD Radeon RX 9070 XT","driver":"AMD proprietary driver 26.8.1 (LLPC)","presents":125,"frame_ms":{"p50":119.541,"p90":122.234,"p99":126.64},"gpu_busy_ms_per_present":90.018,"top_phases_ms_per_frame":{"Driver.Packet":118.492,"Driver.Packet.device_lock":69.187,"Driver.Packet.draw":44.439,"Driver.Draw":44.12,"Driver.Draw.shader_compile_and_link":35.537,"Shader.DrawStage":33.836,"Shader.DrawStage.prepared_invocation":16.829,"Shader.DrawStage.materialize":9.906}}
    • Both traces dropped the worker's slices after 8.3 s and 6.6 s; the summary totals cover the whole window.
  • tools/trace_digest.py of the same two traces (slices kept before the drop):

    • Base: worker busy 87.1 ms per frame, GPU 97.7. Largest slices: Driver.Packet 87.2, Driver.Draw.shader_compile_and_link 78.1, Shader.DrawStage.capture_resources 58.1.
    • Change: worker busy 49.8 ms per frame, GPU 90.0. Largest slices: Driver.Packet 50.0, Driver.Packet.device_lock 29.4, Driver.Draw.shader_compile_and_link 15.8. capture_resources is not among them.
    • The traces are not attached. They stay on the test machine and can be shared.

Checklist

🤖 Generated with Claude Code

savvaniss and others added 2 commits October 20, 2026 12:09
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>
…or the GPU

A COPY_DATA, DMA_DATA or DUMP_CONST_RAM store of up to 64 KiB that the
driver resolves while GPU work is open is recorded into the batch as a
vkCmdUpdateBuffer into the host import, and its range becomes a pending
write. The next draw's resource capture reads the dumped descriptor
table through the flush hook, which submits the batch and waits for the
GPU although the driver already holds the bytes.

The recorder now keeps the bytes of stores wider than the 64-byte label
table too, in record order, and flags them overwritten like table
entries when later GPU work writes over them. Recorder::LookupStoredBytes
composes a range from the newest store of each dword. It refuses a dword
without a store, one a later GPU write covers, a label behind a
completion action and a range under a queued label. Everything recorded
before the store lands first and the store lands before anything
recorded after it, so the bytes are what the next draw reads on the GPU.

classifyPendingWrite answers KnownValue for such a range when the caller
takes the bytes (captures, cached draw and dispatch validation), so the
capture reads them without the wait. Callers that pass no buffer, and
every other pending write, sync as before. APS5_NO_STORED_KNOWN_VALUES=1
turns the path off, and APS5_VERIFY_KNOWN_VALUES=1 checks each served
word against the GPU's; the [capture] profile line now reports both
counts.

Monopoly Plus (CUSA03312) dumps 144- to 512-byte descriptor tables from
constant RAM about 100 times per frame on its language screen, each
followed by a draw whose capture waited about 1 to 2 ms for the GPU.
That screen now runs at about 8.3 instead of 6.1 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 for the changes that are not PS4-only, and on top of boykopovar#9431 for the rest, 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. #8 and #10 to #15 stack on each other, so one upstream pull request per commit, each depending on the one before, would keep them reviewable.

AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

@savvaniss

Copy link
Copy Markdown
Author

Moved upstream with #11 and #21 as boykopovar#9898 on main, one commit each. Closing this one.

@savvaniss savvaniss closed this Oct 22, 2026
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