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>
|
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 |
|
Moved upstream with #10 and #21 as boykopovar#9898 on |
What
A label or store into memory no host import covers (
WriteLabelOnGpureason 3) makes the recording thread wait for all recorded work (WaitIdle) and then write it with the CPU. c9ab6a7 chose that over a store at batch reap because a later label stored on the GPU could become visible first (boykopovar#1458).VideoOut's buffer labels hit that path on every PS4 flip.
PatchFlipin libSceGnmDriver writes 1 toVideoOutBufferLabelAddress(handle) + index * 8withWRITE_DATAbefore the flip packet. That address isbufferLabelsinside VideoOut's host-side config object, and no guest allocation covers it. So once per frame the draw committer rancommitLabel, found no import and waited for the device under the GPU mutex. The queue worker then waited for the committer at the nextDUMP_CONST_RAM. This is the ~69 ms per frame that #10's numbers showed asDriver.Packet.device_lock: that timer mark covers the draw pipeline drain.This PR stores such labels on the GPU instead:
Graphics::UnregisteredHostImportimports the pages holding the label's bytes, rounded to the device's import alignment. It does so only when no guest allocation range overlaps them and, on Windows, every page is committedMEM_PRIVATEmemory with exactlyPAGE_READWRITEprotection in a single allocation.WriteLabelOnGpuuses that import whenHostImportForfinds none. It records the store into the open batch as for any imported label, andRecorder::Keeps the import with that batch so the buffer outlives the store.libSceAgcDriverdebt entry for unimported labels now names what still waits.Nothing depends on the title: any
RELEASE_MEM,WRITE_DATA,DMA_DATA,COPY_DATAorDUMP_CONST_RAMtarget in host memory outside the guest registry takes this path (VideoOut's buffer labels, a label on a native thread stack).The second commit,
75bc9a49b7, fixes a driver test the first one broke. ADMA_DATAcopy over 64 KiB 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. Before the first 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, andagc_driver's copy behind a label into its destination drained.This branch is #10's commit
edf584d568plus these two; review4e16f45972and75bc9a49b7.Tested
Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, on boykopovar#6977's head
93eeee014with #8 and #10, which this branch stacks on.agc_driver_unregistered_label_on_gpu(new, Vulkan):VirtualAllocblock that is not registered returns reason 0, and the word stays 0 until the batch is submitted.It passes on the RX 9070 XT. Without the driver change it fails with "a label in unregistered host memory returned reason 3 instead of 0". The existing
agc_driver_unimported_label_order(PPSA21567: submission stops on "unsupported PM4 packet type: header 0x00000001" where a RELEASE_MEM header is expected boykopovar/AnyPS5#1458's case, a label in the test image's static data) still passes; that memory isMEM_IMAGEand keeps the wait.Validation layer: 48 focused tests on the base (perf(agc): read recorded store bytes in captures instead of waiting for the GPU #10's build,
edf584d568) and the same 48 plus the new one here, on the RX 9070 XT (ANYPS5_GPU=AMD), withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. They are perf(agc): read recorded store bytes in captures instead of waiting for the GPU #10's set plus every label, flip, DMA andWRITE_DATAtest:agc_dma_data_tests,agc_write_data_patch_tests,agc_driver_flip,agc_driver_flip_compute,agc_driver_pipelined_dma,agc_driver_write_data_written_aheadand thevideo_out_flip_*modes. All pass, except the 11video_out_flip_*modes that ctest skips on both sides (the build runs them under SDL'soffscreendriver, which has no Vulkan on Windows).VUID-vkCmdPipelineBarrier-srcAccessMask-02815(agc_unit_shadow,agc_shadowed_key_stores),VUID-vkBeginCommandBuffer-commandBuffer-00050(agc_driver_partially_resident_pending_stores) andVUID-vkDestroyDevice-device-05137(agc_driver_vertex_target_range_copied).was not found but was requested by env var VK_INSTANCE_LAYERS.video_out_flip_testsrun directly withSDL_VIDEODRIVER=windowsunder the same layers, both sides.labels,labels_main,lifetime,reopen,decode,controls,overlayandunopenedpass with no VUID line.ps4,eopandeop_mainfail the same way on both sides: on feat: run PS4 games on the AGC driver — Limbo (CUSA01664) in game (integration branch) boykopovar/AnyPS5#6977's branch the test's 7-dwordRELEASE_MEMis rejected as an invalid packet size, andps4stops at "a PS4 buffer set was changed to tiled".eop_aftergpuexits 127 on both. None of that involves this change.agc_driver(existing) failed on the first commit. ItstestCopyIntoHostMemoryruns a plain copy into astd::vectorand a copy behind aWRITE_DATAinto the same vector. The bytes were right in both, but the run behind the label failed with "a copy into host memory drained instead of syncing its source" (a temporary tag on the message showed it was that run, not the plain one). With the second commit it passes 10 runs out of 10, andagc_driver_unregistered_label_on_gpustill passes 10 out of 10.Validation layer for the second commit: the 49 tests above plus
agc_driver, on the first commit (4e16f45972) and on the second, with the same GPU and environment.agc_driverfails and the other 38 that run pass.video_out_flip_*modes are skipped on both sides, as above.VUID-vkDestroyDevice-device-05137inagc_driveron both.agc_driver_store_over_untrackedfailed once with "the result was never held pending". It submits only register writes and dispatches, so it never reaches the changedDMA_DATApath. It passed in the second full run and in 20 repeats.The Monopoly numbers below are from the first commit. The second changes only
DMA_DATAcopies over 64 KiB into host memory that no import covers.tools/check_conventions.py --base edf584d568passes.tools/pr_overlap.py --repo Get-fix/AnyPS5 --base ps4/limbo-gpureports 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, and perf(recompiler): translate GCN buffer formats without a private table #12 to perf(agc): check a raw shader's address range only when its snapshot is read again #15, which stack on this branch.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 and #10, plus local stand-ins. Base is that stack (2c09e4328d), and change is the same stack with this commit cherry-picked (684cb22e80).Profile of the base (
APS5_PROFILE_DRAW=1) on the language screen, per 10 s:DUMP_CONST_RAM.labelsite 84 times (once per flip) for 5.2 to 5.5 s, at most 67 ms, almost all of it in GPU waits under the lock. Every idle sync on the[recorder]line came fromcommitLabel'sWaitIdle.WRITE_DATAof 1 with reason 3, alternating between two addresses 8 bytes apart and waiting 62 to 67 ms. The memory is private read-write heap with no registered range, and the writer isPatchFlip.The same profile with the change: 84 label holds in 30 ms (at most 0.4 ms), no GPU wait under the lock, 0.3 s of pipeline drains.
Alternating runs,
APS5_TRACE_SUMMARY_EVERY=15with a 120:15 window, both builds on the language screen from about 30 s:device_lockms/framememory_waitms/framerender_fence_waitms/frameThe frame rate does not change: this screen is GPU-bound. Each frame's command buffer starts with a
WAIT_REG_MEMon a buffer label that the previous flip releases, and that flip waits for the frame's GPU work. The time the worker spent waiting for the device lock is now spent in that wait, and the presenter waits for the GPU instead of the committer. The change removes a device drain under the GPU mutex once per flip; this title's pacing hides it.Where the ~90 ms of GPU time per present goes, measured with temporary per-draw timestamps keyed by pixel shader variant (a local hack, not in this PR).
[gputime]puts it all in thedrawclass; labels, uploads, write-backs and the present blit take under 0.3 ms.APS5_NO_HOST_IMPORT=1, so reading buffers from host memory is not the cause, and they do not follow the index count. That points at the execution of those recompiled shaders, a separate investigation.Summary lines of the first pair:
{"commit":"2c09e4328dc6","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":126,"frame_ms":{"p50":119.365,"p90":120.376,"p99":141.206,"max":141.665},"gpu_busy_ms_per_present":90.208,"top_phases_ms_per_frame":{"Driver.Packet":118.356,"Driver.Packet.device_lock":68.705,"Driver.Packet.draw":44.898,"Driver.Draw":44.572,"Driver.Draw.shader_compile_and_link":36.066,"Shader.DrawStage":34.068,"Shader.DrawStage.prepared_invocation":16.661,"Shader.DrawStage.materialize":10.099},"trace_dropped":true,"trace":"aps5-trace-2c09e4328dc6-27408.json.gz"}{"commit":"684cb22e80c4","dirty":false,"env":{...same...},"gpu":"AMD Radeon RX 9070 XT","driver":"AMD proprietary driver 26.8.1 (LLPC)","os":"Windows 10.0.26300","resolution":"1920x1080","presents":125,"frame_ms":{"p50":120.123,"p90":121.942,"p99":123.349,"max":124.271},"gpu_busy_ms_per_present":90.867,"top_phases_ms_per_frame":{"Driver.Packet":118.599,"Driver.Packet.memory_wait":63.895,"Driver.Present":63.634,"Driver.Present.render_fence_wait":57.711,"Vulkan.Retire":57.71,"Vulkan.Retire.wait":57.702,"Driver.Packet.draw":44.046,"Driver.Draw":43.716},"trace_dropped":true,"trace":"aps5-trace-684cb22e80c4-28284.json.gz"}tools/trace_digest.pyof the same two traces (slices kept before the drop):Driver.Packet49.8,Driver.Packet.device_lock29.7,Driver.Packet.draw19.4.Driver.Present63.6,Driver.Present.render_fence_wait57.7,Driver.Packet51.3,Driver.Packet.memory_wait28.7.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)🤖 Generated with Claude Code