Repository navigation
Conversation
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>
A label or store into memory no host import covers made the recording thread wait for all recorded work and write it with the CPU (boykopovar#1458). VideoOut's buffer labels live in host memory no guest allocation covers, so every PS4 flip label drained the device under the GPU lock: the draw committer waited about 63 ms per frame and the queue worker waited for the committer at the next DUMP_CONST_RAM. Such memory is now imported for the batch that stores into it, when its pages are committed private read-write memory of one allocation and no guest range overlaps them. The GPU stores the label in stream order, as the console's CP does. Memory that fails those checks or the import keeps the wait. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…raining A DMA_DATA copy into host memory that no import covers waits for the batches that write its source (Recorder::SyncThrough) and copies on the CPU, unless something can still store over its destination; then it drains the device. Until the previous commit a label into such memory was written by the CPU after a drain, so nothing was pending there. Now that label is a GPU store in the open batch, and a copy behind a label into its destination drained: agc_driver failed in its label case with "a copy into host memory drained instead of syncing its source". The copy now waits for the batches that store into its destination as it does for its source, then checks again. Only what still stores there after that wait (a storage image's write-back, a unit shadow, a label another queue has not recorded yet) drains as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 tasks done
Registration modules read a GCN V#'s word 3 in the shader, and gcnWord3 mapped its DATA_FORMAT and NUM_FORMAT through a 128-entry Private array that every buffer access stored again before indexing it. Drivers keep that array in per-invocation scratch: on the RX 9070 XT each pixel shader of Monopoly Plus's language screen used 528 bytes of scratch and wrote the table up to 60 times per invocation. The lookup is now a helper function that packs the table four entries to a word and picks the word with a select tree, so it stays in registers and each access calls it once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…are unchanged InvocationFor linked the user-data callees of a compute shader or GCN vertex shader on every draw and dispatch: it decoded the whole program, searched it for s_swappc calls through user data, read each callee from guest memory, measured it and linked the result. On Monopoly Plus's language screen that decoding took about 20% of the queue worker. The registered program's decoded call sites are now kept with its prepared state, and so are its last eight links: the callee addresses, the callee words and the linked code. A link is reused when the user data points at the same addresses and the guest memory there still holds the same words; otherwise the callees are read and linked as before. Programs that load call targets from a table keep their call sites but link every time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… hit The result memo keeps the last 256 materialized results of each shader source and reuses one when a later capture has the same snapshot. When a title's draws change their descriptors every time, every lookup misses: the snapshot is hashed, the new result inserted and the oldest one destroyed, all on the queue worker under the source's mutex. On Monopoly Plus's language screen 0.7% of about 300,000 lookups per 10 s hit, and materializing took twice as long as without the memo. Each source now counts its lookups in windows of 256. A window with fewer than one hit in eight sends the next 4096 materializations of that source straight to materializeResult without hashing, looking up or inserting; the memo then probes again, so a source whose snapshots start repeating gets it back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…is read again ReadRawShader checked that its first four bytes were mapped before looking the address up in its snapshot cache. A cached snapshot is then compared with the guest bytes by CompareMapped, which walks the same page states and answers Unmapped for a page that is no longer readable, so on a cache hit the range check repeated a page walk whose answer the compare already gives. DecodeProgramsCurrent calls ReadRawShader for each raw program of every draw that reuses a kept decode; on Monopoly Plus's language screen that check took about 4% of the queue worker. The check now runs only when the snapshot is read again from guest memory: on a cache miss, or when the compare finds the bytes changed or unmapped. An address that was never cached still fails it first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
savvaniss
force-pushed
the
perf/ps4-raw-shader-recheck
branch
from
October 21, 2026 11:42
c015ae7 to
b8a143f
Compare
11 tasks done
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 AI-assisted: yes (Claude Code) 🤖 Generated with Claude Code |
This was referenced Oct 21, 2026
Author
|
Moved upstream with #13 as boykopovar#9899 on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ReadRawShader(a PS4 program with no header, read from guest memory by its address) began withGuestMemory::CheckRangeon its first four bytes, then looked the address up in its snapshot cache. A cached snapshot is then compared with guest memory byGuestMemory::CompareMapped, which walks the same page states and returnsUnmappedfor a page that is no longer readable. So on a cache hit the range check was a second page walk whose answer the compare gives anyway.DecodeProgramsCurrentcallsReadRawShaderfor each raw program of every draw that reuses a kept decode. On Monopoly Plus's language screen, after #14, a sampling profile of the queue worker put 8.2% of its time inReadRawShader;CheckRangewas about half of that.This PR runs the range check only when the snapshot is read again from guest memory: on a cache miss, or when the compare found the bytes changed or unmapped. Nothing else changes:
Unmapped, reaches the check and throws as before.Tested
Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, on boykopovar#6977's head
93eeee014with #8, #10, #11, #12, #13 and #14, which this branch stacks on.ReadRawShadercases inagc_driver(tests/Submit.cpp) cover the paths it touches and pass: snapshot reuse, rewritten code, concurrent readers, eviction, misaligned and null addresses, and a cached program and tail madePAGE_NOACCESSafter they were cached ("raw compute reused inaccessible cached code"), which now goes through the moved check.agc_driveras a whole failed on this branch and on its base at a later case,testCopyIntoHostMemory("a copy into host memory drained instead of syncing its source"), which failed from perf(agc): store labels in unregistered host memory on the GPU #11 on. perf(agc): store labels in unregistered host memory on the GPU #11 now carries the fix (75bc9a49b7) and this branch was rebased onto it, with the patch unchanged. On the rebased headb8a143fb84,agc_driverpasses, among perf(agc): store labels in unregistered host memory on the GPU #11's 49 focused tests plusagc_driveron the RX 9070 XT with the validation layer. All 50 pass or skip as they do on perf(agc): store labels in unregistered host memory on the GPU #11 (the 11 VideoOut flip tests skip with no display), with the same VUIDs per test.c957431190) and here, on the RX 9070 XT (ANYPS5_GPU=AMD), withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: perf(recompiler): bypass a source's result memo while it is not being hit #14's 59 plusagc_driver. Both sides give the same results: everything passes exceptagc_driver(thetestCopyIntoHostMemoryfailure above, fixed by the rebase) andagc_driver_oversized_dispatch, which skips itself.VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605(20 inagc_driver_prepared_exports) andVUID-vkDestroyDevice-device-05137(2 inagc_driverand in each of sevenagc_driver_prepared_shadersmodes).was not found but was requested by env var VK_INSTANCE_LAYERS.tools/check_conventions.py --base 8ff66665a1(the rebased perf(recompiler): bypass a source's result memo while it is not being hit #14) passes.tools/pr_overlap.py --repo Get-fix/AnyPS5 --base ps4/limbo-gpureports only fix(agc): PS4 display, textures and GCN instructions for CUSA03312 #1, on theShaderDiskCache.cpplines 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, #8, #10, #11, #12, #13 and #14, plus local stand-ins. Base is that stack (819cd3db26), and change is the same stack with this commit cherry-picked (cb626a70e8).Worker profile (
APS5_SAMPLE_WORKER, the same 40 s of the language screen in each build, 2,562 samples each):DecodeProgramsCurrentReadRawShaderCheckRangeunder itCompareMappedunder itAlternating runs,
APS5_TRACE_SUMMARY_EVERY=15with a 120:15 window, both builds on the language screen:Driver.Packetms/frameThe means are 26.3 and 26.7 fps. The saving is about 3% of the worker's time, smaller than the run-to-run spread of these windows (the third change run had a 45 ms p90), so these runs do not resolve a frame-rate change; the profile above is the measurement.
Summary lines of the first pair:
{"commit":"819cd3db2630","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","window":{"spec":"seconds 120:15","first_present":3744,"ms":15011.733},"presents":395,"frame_ms":{"p50":37.904,"p90":39.212,"p99":41.530,"max":57.233},"gpu_busy_ms_per_present":13.184,"worker_busy_pct":{"queue worker 0x0":96.232},"top_phases_ms_per_frame":{"Driver.Packet":36.474,"Driver.Packet.draw":25.080,"Driver.Draw":24.757,"Driver.Draw.shader_compile_and_link":16.413,"Shader.DrawStage":14.794,"Shader.DrawStage.capture_resources":7.109,"Driver.Packet.device_lock":6.646,"Shader.DrawStage.materialize":5.454},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":3.577,"events_lost":839072,"totals_full":false}},"trace":"aps5-trace-819cd3db2630-35708.json.gz"}{"commit":"cb626a70e8ae","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","window":{"spec":"seconds 120:15","first_present":3828,"ms":15012.513},"presents":419,"frame_ms":{"p50":35.608,"p90":37.677,"p99":39.354,"max":50.076},"gpu_busy_ms_per_present":13.860,"worker_busy_pct":{"queue worker 0x0":96.109},"top_phases_ms_per_frame":{"Driver.Packet":34.329,"Driver.Packet.draw":23.134,"Driver.Draw":22.824,"Driver.Draw.shader_compile_and_link":15.864,"Shader.DrawStage":14.352,"Shader.DrawStage.capture_resources":6.875,"Driver.Packet.device_lock":6.550,"Shader.DrawStage.materialize":5.268},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":3.702,"events_lost":795786,"totals_full":false}},"trace":"aps5-trace-cb626a70e8ae-27232.json.gz"}tools/trace_digest.pyof the same two traces (slices kept before the drop):batch13.2,Driver.Packet7.1,Driver.Packet.draw5.3,Driver.Draw.shader_compile_and_link2.6,Driver.Packet.device_lock1.4.batch13.9,Driver.Packet6.6,Driver.Packet.draw4.8,Driver.Draw.shader_compile_and_link2.5,Driver.Packet.device_lock1.4.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)8ff66665a1plus one; review the top commitb8a143fb84)🤖 Generated with Claude Code