perf(agc): keep constant RAM dumps and unregistered labels on the GPU without draining #9898
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9898"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-22T20:49:54Z.
What
Get-fix/AnyPS5#10, #11 and #21, moved upstream as one pull request: each removes a wait the queue worker or the committer made for a store the GPU was about to make. None is PS4-only, so it goes straight on
main. Each is its own commit, in this order:c8e2a98755,df808a4807,f137c98218. After review and CI,mainis merged in (lastb7488e1ff5, in3cd01b28ab) and the fixes follow, described under Follow-ups below.1. Captures read recorded store bytes instead of waiting for the GPU (Get-fix/AnyPS5#10)
A PS4 title that uses the constant engine builds its descriptor tables in constant RAM and dumps them to memory with
DUMP_CONST_RAMbefore each draw. While GPU work is open,preparePacketMemoryresolves such a store (Pm4::ResolveStore, up to 64 KiB, alsoCOPY_DATAandDMA_DATA) andVulkanDevice::WriteLabelOnGpurecords it into the batch as avkCmdUpdateBufferinto 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 commit lets a capture read those bytes instead of waiting:
LabelTableBytes(64). Wider stores were ranges only (wideLabels). They now keep their bytes and a record sequence too.markOverwrittenflags them like table entries when later GPU work writes over them, and they leave with their batch as before.Recorder::LookupStoredBytescomposes 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, any range under a queued label and, since7aa3c8f63d, any store of a batch whose submit has started (see Follow-ups).Driver::classifyPendingWriteanswersKnownValuewith those bytes when the caller passes a buffer for them. Callers that do are the capture's word reads (ShaderMemory),captureStableandvalidateCaptured. 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=1turns the path off. WithAPS5_VERIFY_KNOWN_VALUES=1each 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.
2. Labels in unregistered host memory are stored on the GPU (Get-fix/AnyPS5#11, with its follow-up fix folded in)
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.c9ab6a72a5chose that over a store at batch reap because a later label stored on the GPU could become visible first (#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 commit 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.c14d8edb47Linux checks the pages too (one private anonymous read-write mapping in/proc/self/maps), and sincecd2e19f6f9the import is made only while no copied writer is listed and no completion store is pending.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 commit also carries the follow-up
75bc9a49b7from Get-fix/AnyPS5#11, which fixes a driver test the import 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.3.
DUMP_CONST_RAMis queued behind pipelined draws (Get-fix/AnyPS5#21)A
DUMP_CONST_RAM(PM4 0x83) on the graphics queue drained the draw pipeline.keepsDrawPipelinedoes not keep 0x83, so the queue worker waited until the committer had recorded every queued draw, thenpreparePacketMemoryrecorded the dump's GPU store itself. A PS4 title's constant engine dumps a descriptor table before many of its draws. On the board of Monopoly Plus (CUSA03312),APS5_PROFILE_DRAW's[draw] pipelinedline counted 4,700 to 5,400 drains a second, nearly all by opcode 0x83, and the worker waited 3.0 to 3.5 s of every 10 s in them.This commit queues the dump instead:
Pm4::ResolveStore, as before) and queues their store as a pipeline item (Driver::enqueueConstantRamDump). The committer records it in stream order with the draws around it through the same store path as a queued DMA_DATA store (Driver::commitStore, renamed fromcommitDmaStore).DrawPipeline::StoredBytesanswers for a range from the newest queued item that writes it: that item's bytes when it is a store covering the whole range, unknown when it is any other item.Driver::queryPendingWritegives a capture those bytes as known values instead of draining, and drains as before when the answer is unknown. A page under a queued store is read word by word without draining. WithAPS5_VERIFY_KNOWN_VALUES=1it drains first, so each served word is checked against the stored one.The other reads the worker makes between the enqueue and the commit:
0x63/0x64/0x9fpackets already drain on an overlap with any queued write (DrawPipeline::Overlaps); the queued store's range is one.WAIT_REG_MEMon a dumped word reads the queued value throughDrawPipeline::PendingLabel, which reads the stored bytes of a store item as it does a label's.Graphics::DecodeVertexStageInfo, attribute words and vertex V#s) drains and decodes again when its reads overlap a queued write. This branch first added that drain itself;main's #7691 (DecodeOrderedVertexStageInfo) now does it, and the merge keepsmain's helper. PS4 programs have no AGC header, so this never runs for them.Dumps the worker cannot resolve, dumps outside writable guest memory, predicated dumps and dumps while labels are deferred take the old path. A dump of no words stores nothing and no longer drains.
APS5_PIPELINE_DRAIN_DUMPS=1restores the drain for every dump, likeAPS5_PIPELINE_DRAIN_FILLSfor fills.main's draw pipeline now also orders queued reads (Enqueue'sreads,HeldReads), counts queued writes and runs draws through the optional draw finisher (APS5_DRAW_PIPELINE).EnqueueStoregoes through the same enqueue, which drains a busy finisher first; a queued store item carries no reads; andStoredBytesrefuses a range the finisher still holds as well as anything a queued non-store item writes.Follow-ups after review and CI
71bcb4a8d2mergesmain9c6d153dec. The resolution keepsmain's draw pipeline, finisher and packet loop, and takesmain's ordered vertex-table decode (#7691) inDraw.cpp.WriteLabelOnGpukeeps the unregistered import ahead of #8180's completion stores.cd2e19f6f9fixes the Linux CI failure ofagc_driver_compute_pipeline_outside_gpu_mutex("the first dispatch stored 0"):WRITE_DATAafter it was stored by the GPU into an unregistered import, so the label was visible first.7aa3c8f63d(first review, point 1): recorded store bytes are refused once their batch's submit has started.submitStartedbeforevkQueueSubmit. The lookup does not query the fence: captures run without the GPU mutex, and a label in the middle of a batch is visible before its fence signals.c14d8edb47(first review, point 3): on Linux,UnregisteredHostImportchecks that the range lies inside one private anonymous read-write mapping (rw-p, inode 0). An import does not fail for every such page: AMD's Windows driver imports a mapped view of a section.0a08a3b019:mainnow queues queue-0DMA_DATAby default (ce6865fc0d). Its committed copy into host memory now waits for the batches that store into its destination, as the immediate path above does.agc_driverfailed without it.3cd01b28abmergesmainb7488e1ff5.0bc7829562fixes the heap corruption XairRrR found (agc_driver_queued_constant_ram_dumpaborting on Linux withfree(): chunks in smallbin corrupted):DrawPipeline::enqueueandDrawFinisher::Enqueueleft retired items in a thread-local vector until the thread's next enqueue. At thread exit that vector is destroyed with the thread's other thread-locals, in reverse order of construction.~ShaderMemory, reached from a retired draw item, returns its pages topagePool(), also a thread-local on Linux. If the pool was constructed after the vector it is already gone, and the page goes into its freed buffer. ASan on the unfixed tree reports a heap-use-after-free at thatemplace_back, from__call_tls_dtors.APS5_PIPELINE_DRAIN_DUMPS=1only hid it, because the test then stops at its first assert, before that second enqueue.mainhas the same two vectors.Enqueuereturns, after the lock is released, so nothing is left in them at thread exit. They keep their storage.70d8cce27d(first review, point 2, option B as chosen on this pull request):VideoOutDriver::Openwaits for the driver (AgcDriverWaitIdle) before it replaces a closed port's configuration.VideoOutConfig::bufferLabelsbefore the batch with PatchFlip's GPU store ran.Openchecks the port again afterwards, since anotherOpenmay have run meanwhile.sceVideoOutOpenreturns stalls the reopen with it. That limit is in thelibSceVideoOutdebt file.4647d9c464: the Linux page check uses thePROCMAP_QUERYioctl on/proc/self/maps(Linux 6.11 and later), and reads the file as text only when the ioctl fails.fb1551442bmergesmainde2ba4cecb. Two conflicts, both lines added on each side: the recorder tests'PATHlist inCMakeLists.txtand the argument dispatch intests/Recorder.cpp. Both sides are kept.The per-label import is not cached: an import that outlived its batch would pin memory its owner may free, and host memory has no hook to invalidate it. On the RX 9070 XT a label into unregistered memory costs about 300 us (a registered one 0.4 us), against the ~63 ms wait it replaces. The Linux check takes 0.4 us with the ioctl at any depth; the text fallback takes up to 11 ms at 20,000 mappings (about 0.6 us per mapping ahead of the label's).
Tested
Merge of
maind1ae628bc2, 3 Nov, and a variant-validation fix. Headb8c3f25cdf(mergef070b16201). Conflicts: the[capture]profile line inShaderMemory.cpp(main's line with this branch's known-value verified/mismatch counters), the option list intests/Recorder.cpp(both kept) and the WindowsPATHlist inagc_driver_recorder_tests.cmake(main's list plusagc_recorder_stored_bytes). After the merge,agc_driver_queued_constant_ram_dumpfailed on AMD as oneandonlydean reported: a later draw reused a cached variant andDriver::validateVariantdrained withDrainReason::Capture.b8c3f25cdf: when every queued item over the variant's runs is a store whose bytes the pipeline holds,validateVariantreturnsDifferingwithout draining, so the capture serves the queued bytes; other overlaps, andAPS5_VERIFY_KNOWN_VALUES, still drain. Comparing the queued bytes with the variant and keeping it when they matched was tried first and is wrong: the later data-word check reads guest memory that still holds the old table, and draw 1 wrote 64 instead of 255. Windows, WinLibs GCC, Release, AMD RX 9070 XT, validation layer,ANYPS5_NO_SHADER_CACHE=1:agc_driver_queued_constant_ram_dumpfails on the merge without the fix (1 capture drain) and passes 3/3 with it, and passes withAPS5_VERIFY_KNOWN_VALUES=1; 49/49 of the focused set pass (draw_cache_relocation*,draw_cache_reuse*,draw_data_hit_user_words*,dispatch_data_hit_words,draw_pipeline_*, the*_draw_pipelinevariants of bda span, buffer load/store, copied writer, depth storage reuse, unsupported buffer type and write ranges,dumped_constant_capture, bothunregistered_label_*,agc_driver_recorder,agc_recorder_*,agc_queued_write_groups);agc_recorder_kept_byteswas not built. NoVUID-, 54 device lines all RX 9070 XT.check_conventions.pypassed. Not rerun: the same set onmain, Linux, the full suite, games, and a paired trace for the speed claim.Merge of
mainf2d874c1fd, 1 Nov. Heada814af06ee. The only conflict was in the Linux includes ofGuestBufferMemory.cpp:main's macOSudmabufstand-in and this branch's<linux/fs.h>(forPROCMAP_QUERY) are both kept, with<linux/fs.h>on the non-Apple side. On the RX 9070 XT, 13 of 13 pass with noVUID-line and every device line naming it:agc_driver,agc_driver_pm4,agc_shader_memory,agc_driver_compute_pipeline_outside_gpu_mutex,agc_driver_draw_pipeline_retired_items,agc_driver_dumped_constant_capture,agc_driver_queued_constant_ram_dump,agc_driver_unregistered_label_behind_write_back,agc_driver_unregistered_label_on_gpu,agc_driver_vertex_table_read_order,agc_recorder_stored_bytes,agc_recorder_command_buffer_release,video_out_flip_reopen. Linux: WSL Ubuntu, g++ 15.2.0 compiledGuestBufferMemory.cppandPipelineJournal.cpponly (the merge changed no struct under the size guards); nothing was linked or run there. Not rerun: the rest of the focused set, each test only once rather than three times, macOS, games.Windows 11 Pro 26300, WinLibs GCC 15.2.0, Release, AMD Radeon RX 9070 XT (driver 32.0.31041.1004), Vulkan SDK 1.4.363.0. Every run used
ANYPS5_GPU=AMD,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, withctest -V, three times each, onmainb7488e1ff5and on this branch at4647d9c464. The current headfb1551442b(mainde2ba4cecbmerged) had the smaller rerun in the last row and the note under the table.Focused set:
agc_driver,agc_shader_memory,agc_driver_pm4and its mode and replay tests,agc_driver_compute_pipeline_outside_gpu_mutex, every pipelined, label, constant-store, copied-writer and DMA test with their draw-pipeline variants,agc_driver_vertex_table_read_order, the recorder tests andvideo_out_flip_*. That is 176 tests onmain, plus this branch's 6 on the branch.mainb7488e1ff5, each of 3 runs4647d9c464, runs 1 and 24647d9c464, run 3fb1551442b, each of 3 runsfb1551442b: the focused set without its 17video_out_flip_*tests, plusmain's newagc_recorder_command_buffer_release, which is the 166 above. Both tests behind the conflicts passed in all three runs:agc_recorder_stored_bytesandagc_recorder_command_buffer_release.video_out_flip_reopenandmain's newvideo_out_flip_padstatusran once and passed. Same environment, noVUID-or missing-layer lines, and every device line names the RX 9070 XT.fb1551442b: the other 16video_out_flip_*tests, the mutations below, anything on Linux, andmainde2ba4cecb, so themaincomparison is still theb7488e1ff5row.Notes on the runs at
4647d9c464:agc_driver_pm4_ringin run 3, after 0.05 s: "replace guest placeholder with private memory: Attempt to access invalid address", fromCommitin libc'sWindowsMappings.hppwhile the process sets up the guest arena. This branch does not touch libc. I repeated the test 40 times on each build: 40 of 40 on both. I have not found the cause.agc_driver_copied_writer_label_orderand its drain variant: the device'sminStorageBufferOffsetAlignmentof 4 binds the record in place.VUID-line orwas not found but was requested by env var VK_INSTANCE_LAYERS, and every device line names the RX 9070 XT.New and changed tests, each failing without its part of the change. Every row was run on
4647d9c464, 3 of 3 runs, and not repeated atfb1551442b:agc_driver_dumped_constant_capture, dump read by the next captureAPS5_NO_STORED_KNOWN_VALUES=1: "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_driver_dumped_constant_capture, CPU write after the dump's label7aa3c8f63d's wide-store check, or the flag: "the draw after the guest rewrote a dumped constant to 0.5 once the label behind the dump had landed wrote 255"agc_recorder_stored_bytes7aa3c8f63d's wide-store check: "a wide store is served after its batch was submitted"; its table check: "a label-table store is served after its batch was submitted"agc_driver_unregistered_label_on_gpuMEM_PRIVATEcheck: "a label in a mapped view of a section returned reason 0 instead of 3"agc_driver_unregistered_label_behind_write_back, 8-byte label after a write-back!listedfor labels: "its store landed over the 0 the host stored once the GPU work was done" (reason 5)!listedfor stores: "held 0x6b6b0001 once the GPU ran its batch (reason 0), while the dispatch's record still held 0xc0001000"!storesPendingfor labels: "it landed over the 0 the host stored once the GPU work was done"!storesPendingfor stores: "held 0x1 once the GPU ran its batch (reason 0), while the earlier label in registered memory, stored when its batch is reaped, still held 0x0"agc_driver_queued_constant_ram_dumpAPS5_PIPELINE_DRAIN_DUMPS=1: "a DUMP_CONST_RAM drained the draw pipeline 1 times"agc_driver0a08a3b019: "a copy into host memory drained instead of syncing its source"agc_driver_draw_pipeline_retired_itemsDrawPipeline::enqueue: "a retired draw pipeline item stayed in the enqueuing thread's storage after Enqueue returned"; inDrawFinisher::Enqueue: "a finished draw finisher job stayed..."video_out_flip_reopen(a flip and a label store of the old configuration gated behind the queue)70d8cce27d's wait: "reopen replaced the port's configuration while a flip and a label store of the previous one were in flight"The CI failure, reproduced on the RX 9070 XT: a local copy of
agc_driver_compute_pipeline_outside_gpu_mutexwith its slots inVirtualAllocmemory (MEM_PRIVATE, so it is imported) failed "the first dispatch stored 0" in 5 of 5 runs with the import behaving as atbd31efba93, and passed 5 of 5 withcd2e19f6f9. The test file in this pull request is unchanged. On Windows the test's own static arrays areMEM_IMAGEand take the wait.Linux, all at
4647d9c464, before the merge ofde2ba4cecb(WSL Ubuntu, g++ 15.2, Release, Unix Makefiles, lavapipe with LLVM 21.1.8, no validation layer installed). I bypassed two configure checks in that copy only, for the XRandR and audio development files; nothing else differs from that commit.agc_driver,agc_driver_compute_pipeline_outside_gpu_mutex,agc_driver_queued_constant_ram_dump,agc_driver_copied_writer_label_orderand its drain variant, and the Linux cases ofagc_driver_unregistered_label_on_gpu.video_out_flip_*tests includingvideo_out_flip_reopen(SDL has no X11 or Wayland in that copy, so no Vulkan window), and 8 tests whose device needs are not met on lavapipe (host imports of watched memory, deferred settles, a pipeline cache). So the VideoOut reopen test has not run on Linux.agc_driver_queued_constant_ram_dump: at the unfixed merge3cd01b28ab, 5 runs gave 3 aborts withfree(): chunks in smallbin corrupted, 1 segfault and 1 pass. At4647d9c464, 20 of 20 pass.ANYPS5_ENABLE_ASAN=ON): at3cd01b28ab, a heap-use-after-free as described above. At4647d9c464, 0 errors inagc_driver_queued_constant_ram_dump(3 runs),agc_driver_draw_pipeline_retired_items, both unregistered label tests,agc_driver_dumped_constant_captureandagc_driver_compute_pipeline_outside_gpu_mutex.PROT_NONE, shared anonymous, a private file mapping, the stack and an unmapped address. 0 failures on either path. The text fallback has run only there, since this kernel (6.18) has the ioctl.Graphics/src/PipelineJournal.cppandcore/shader/recompiler/ShaderDiskCache.cpp, with their Linux-onlysizeofguards, compile.mainwas not built on Linux. The merge ofde2ba4cecbchanges neither file, nor a guard or guarded struct in AGC, and Linux was not compiled again atfb1551442b.The numbers below were measured before the follow-ups. Since then, recorded store bytes are served only while their batch is open, and an unregistered label waits while a copied writer or completion store is pending. Each can bring back part of a wait the numbers show removed. No game was run for this update, and the title still needs #9432 to run on
main, so this is not themaincomparison MarcZX10 and XairRrR ask for.Monopoly Plus (CUSA03312). The title doesn't run on
main: it needs #9430 to #9432. As agreed on #6977, these numbers come fromps4/limbo-gpuat93eeee0141(#6977's head then), with and without the change, on the local stack the title needs to start: the Get-fix pull requests named with each pair, and local stand-ins forsceGnmDrawInitDefaultHardwareState200andsceGnmUpdate*Shader. The base and change commits named with each pair are commits of that local stack, which isn't published. Base and change alternated on the same machine and scene.9c5c8619f7, change2c09e4328d, both with Get-fix/AnyPS5#1, #2, #5 and #8:shader_compile_and_linkms/framecapture_resourcesms/framedevice_lockms/frameSummary lines, written before the summary had
traceandwindow: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}}2c09e4328d, change684cb22e80, both with Get-fix/AnyPS5#1, #2, #5, #8 and #10. The fps stays the same, because the screen was GPU-bound then. The committer's ~63 ms per flip under the GPU mutex is gone.device_lockms/framememory_waitms/framerender_fence_waitms/frameSummary lines, written before the summary had
window. The two traces they name are no longer on the machine that recorded them, so they cannot be attached; the digest below is what remains:Base:
{"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"}Change:
{"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 two tracesBase,
aps5-trace-2c09e4328dc6-27408:seconds 120:15 from present 1906: 126 presents, frame p50 119.4 / p90 120.4 / p99 141.2 / max 141.7 ms, GPU busy 90.2 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 1920x1080, commit 2c09e4328dc6, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 90.2, Driver.Packet 49.8, Driver.Packet.device_lock 29.7, Driver.Packet.draw 19.4, Driver.Draw 19.3, Driver.Draw.shader_compile_and_link 15.5, Shader.DrawStage 10.4, Shader.DrawStage.prepared_invocation 3.9
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Change,
aps5-trace-684cb22e80c4-28284:seconds 120:15 from present 1897: 125 presents, frame p50 120.1 / p90 121.9 / p99 123.3 / max 124.3 ms, GPU busy 90.9 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 1920x1080, commit 684cb22e80c4, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 90.8, Driver.Present 63.6, Driver.Present.render_fence_wait 57.7, Vulkan.Retire 57.7, Vulkan.Retire.wait 57.7, Driver.Packet 51.3, Driver.Packet.memory_wait 28.7, Driver.Packet.draw 19.8
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
In each trace the queue worker's event buffer filled 6.6 to 6.7 s into the 15 s window (
trace_dropped_threads). Its later slices are missing from the trace, so the thread, slice and wait lists cover only that part of the queue worker's time.DUMP_CONST_RAM, on Monopoly's idle match board (Get-fix/AnyPS5#21 has the full runs). Pair: base7cee08fdaf, change4dbf61346d, both with Get-fix/AnyPS5#1, #2, #5 to #8, #10 to #15, #19 and a port of #9385. The board goes from 3.8 to 5.5 fps with alternating builds, and from 5.0 to 6.9 fps when the drain is toggled within one run.Summary lines. These runs set no
APS5_TRACE_SECONDS, so they wrote no traces; the digest below reads their summary files:Base (
7cee08fdaf):Change (
4dbf61346d):tools/trace_digest.pyof the two runs' summary filesBase,
7cee08fdaf:20 intervals, 0.0 to 302.0 s, 3852 presents
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 1920x1080, commit 7cee08fdaf5c
Change,
4dbf61346d:20 intervals, 0.0 to 301.3 s, 4485 presents
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 1920x1080, commit 4dbf61346d53
Row 17, 241 to 256 s, is the window of the summary lines above.
tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.pylists these:WriteLabelOnGpuand the debt entry next to this branch's. Whichever lands second has to keep the unregistered import's condition.GuestBufferMemory.cppon macOS and changes the include lines next to this branch's<linux/fs.h>, which then goes behind the same guard.[capture]report line inShaderMemory.cppthat this branch also changes.DrawPipeline.cpp.CMakeLists.txtor the recorder tests.None implements the same thing.
Merge of
maincc26ab4438, 1 Nov. Headbebaf6e59d. The only conflict waslibSceAgcDriver/CMakeLists.txt:mainmoved the AGC test registrations intotests/cmake, andtools/agc_test_split.py resolvemovedagc_recorder_stored_bytesto theagc_driver_recorder_testsfragment.agc_recorder_stored_bytes,agc_recorder_read_list,agc_driver_queued_constant_ram_dumpandagc_driver_graphicspass, 3 of 3 on the RX 9070 XT under the validation layer, noVUID-line. Not rerun: the other tests, Linux, games.Merge of
mainb415263451, 1 Nov. Head87e6918b69. Conflicts inRecorder.hpp,Recorder.cpp,tests/Recorder.cppanddocs/dev/debt/libSceVideoOut.md: this branch'sLookupStoredBytesandmain'sUnlandedOwnLabel(withmain'sANYPS5_PAD_IDENTIFYdebt lines) sit side by side, and both test groups stay in the recorder runs. Windows, RX 9070 XT, same environment as above, one run of a focused set of 31: the recorder'sagc_recorder_stored_bytes,agc_recorder_completion_labelsandagc_recorder_command_buffer_release,agc_driver,agc_driver_same_queue_label_waitand the label-order, constant-store, idle-store and unregistered-label tests with their variants,video_out_flip_reopenandvideo_out_flip_padstatus. 29 passed and 2 skipped (agc_driver_copied_writer_label_orderand its_drainvariant: this device'sminStorageBufferOffsetAlignmentis 4). NoVUID-line, and every selected-GPU line names the RX 9070 XT. Not rerun at this head: the othervideo_out_flip_*tests,agc_shader_memory,agc_driver_pm4and its variants, Linux, and any title. The speed numbers above were not remeasured.Merge of
main4f41f4c375, 3 Nov. Headf160886325. The only conflict was the WindowsPATHlist inagc_driver_recorder_tests.cmake: main's newagc_changed_copyand this branch'sagc_recorder_stored_bytesare both kept. Windows, WinLibs GCC, Release, RX 9070 XT,ANYPS5_GPU=AMD ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: 19 of 19 pass, 3 of 3 runs, noVUID-line, no skip (agc_driver_queued_constant_ram_dump,agc_driver_draw_cache_reuseand its six variants,agc_driver_draw_pipeline_retired_items,agc_driver_dumped_constant_capture, bothagc_driver_unregistered_label_*,agc_driver_vertex_table_read_order,agc_driver_compute_pipeline_outside_gpu_mutex,agc_driver_pm4,agc_recorder_stored_bytes,agc_changed_copy,agc_driver,video_out_flip_reopen). Not rerun: the rest of the recorder set, Linux, games.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
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T03:25:47Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
On current
main(Linux, NVIDIA) the new testagc_driver_queued_constant_ram_dumpaborts in every run with heap corruption. The PR also conflicts withmain, and the VideoOut use-after-free that a maintainer asked to fix with option B is still open on this head.What I ran
0a08a3b019ccac0cd15dbf78339a79f9746e7e54main:3a2b91981651569163768854a1fcdc7193b6667b(the branch is based on9c6d153dec, 3,794 commits behind)git mergeof the head intomainconflicts in two files (see Blocking 1). Both conflicts are mechanical. To build and test the change against currentmain, I resolved them locally:main's lines, plus this branch'sagc_recorder_stored_bytesentry andAPS5_PIPELINE_DRAIN_DUMPSrow. Everything below ran on that resolved merge.Results
main3a2b919816core/libs/prx/libSceAgcDriver/CMakeLists.txtanddocs/dev/ENVIRONMENT.mdgit diff --checktools/check_conventions.py --base origin/mainAll conventions checks passed.libs, resolved merge)agc_driver_queued_constant_ram_dump(Subprocess aborted)agc_driver_queued_constant_ram_dumprepeatsfree(): chunks in smallbin corruptedagc_recorder_stored_bytes,agc_driver_dumped_constant_capture,agc_driver_unregistered_label_on_gpu,agc_driver_unregistered_label_behind_write_backunregistered_label_on_gpu(read-only page, private file mapping, shared anonymous mapping), which the description says first run in CI.agc_driver_compute_pipeline_outside_gpu_mutex(the earlier CI failure)agc_driver,agc_driver_copied_writer_*agc_driver_copied_writer_label_order, which this device does not skipVUID-lines in the merged-tree logwas not found but was requested by env var VK_INSTANCE_LAYERS-j4agc_driver_queued_constant_ram_dump, ctest
Localisation
Under gdb, with stdout flushed at the abort, both cases of the test print their success line first, and the abort follows on another thread as it exits:
With
libc_malloc_debug.soandMALLOC_CHECK_=3, the invalid free shows up at process exit instead, while thread-local storage is destroyed. It happens in a retiredDrawPipeline::Itemvector, which is the thread-local reclaim vector thatDrawPipeline::enqueueswaps retired items into:free(): chunks in smallbin corrupted(2 of 2)APS5_NO_STORED_KNOWN_VALUES=1APS5_VERIFY_KNOWN_VALUES=1APS5_PIPELINE_DRAIN_DUMPS=1(old path)a DUMP_CONST_RAM drained the draw pipeline 1 times(2 of 2), as expectedNegative control
I did not restore the production files from
mainand rebuild. A secondlibSceAgcDriverrebuild did not fit the time I had. Instead I used the switches the PR adds, which put backmain's behaviour on the path each test covers:APS5_NO_STORED_KNOWN_VALUES=1:agc_driver_dumped_constant_capturefails 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" (exit 1).APS5_PIPELINE_DRAIN_DUMPS=1:agc_driver_queued_constant_ram_dumpfails with "a DUMP_CONST_RAM drained the draw pipeline 1 times".Both match the description's table. I did not reproduce the per-condition negative controls for
UnregisteredLabelBehindWriteBackandUnregisteredLabelOnGpu.Findings
Blocking
agc_driver_queued_constant_ram_dumpaborts with heap corruption on Linux, every run (core/libs/prx/libSceAgcDriver/tests/execution/QueuedConstantRamDump.cpp). Both cases pass their assertions, then the process dies withfree(): chunks in smallbin corrupted: 10 of 10 runs, with and without the validation layer. The abort goes away only withAPS5_PIPELINE_DRAIN_DUMPS=1, so it is tied to the queued-dump path (Driver::enqueueConstantRamDump→DrawPipeline::EnqueueStore), not to the stored-known-values lookup. The malloc-debug backtrace points at teardown: aDrawPipeline::Itemholding afinishDrawlambda, and through it aShaderMemory, is freed from the thread-local reclaim vector inDrawPipeline::enqueueduring__call_tls_dtors, which is afterAgcDriverShutdown_nid_postfix(). I have not established whether this is a production lifetime bug that only teardown exposes, or a test teardown problem (the test enqueues a held item on its own thread and then shuts the driver down). Either way, the test fails as merged, and a heap corruption should be understood before the path is enabled by default. Please run it under ASan on Linux, or withlibc_malloc_debugas above, and fix whichever side it is. Your Windows runs were on the9c6d153decbase, so this may also come frommain's newer draw pipeline or finisher code.The PR conflicts with current
main.core/libs/prx/libSceAgcDriver/CMakeLists.txt, in theif(WIN32)set_tests_properties(agc_recorder_read_list ...)list:mainaddedagc_driver_recorderandagc_repeat_storage_guard, and this branch addsagc_recorder_stored_bytes.docs/dev/ENVIRONMENT.md:mainextended theAPS5_PIPELINE_DISPATCHrow, and this branch adds theAPS5_PIPELINE_DRAIN_DUMPSrow after it.Both resolutions are mechanical. The base is far behind, though, so please merge or rebase and rerun the focused set. Finding 1 is what that set shows on current
main.The VideoOut buffer-label use-after-free is still open, and the fix the maintainer chose is not on this head. Your reply laid out the gap, and on 2026-10-25 the maintainer chose option B:
Openwaits for the previous configuration's outstanding GPU work, plus a close/reopen regression test.0a08a3b019predates that answer. I checked the path on the merged tree:UnregisteredHostImport(Graphics/src/GuestBufferMemory.cpp:4238) imports the pages ofVideoOutConfig::bufferLabels(libSceVideoOut/include/VideoOutDriver.hpp:155).WriteLabelOnGpukeeps only the Vulkan import with the batch (Execution/src/VulkanDevice.cpp:2520,:2534), not the heap object behind it.VideoOutDriver::Openreplacescontexts[handle](libSceVideoOut/src/VideoOutDriver.cpp:386-402), andprocessFlipreleases a request on a closed config at:579,:596and:638without waiting for the GPU.So a close and reopen with a flip in flight can free the config before the batch holding PatchFlip's 8-byte store runs. On
main, the CPU writes that label afterWaitIdle. This is a new memory-safety regression on a reachable path, so it belongs in this PR, not in a debt entry. The new debt text atdocs/dev/debt/libSceAgcDriver.md:163does not mention it either.Non-blocking
Linux page check cost.
privateAnonymousReadWrite(Graphics/src/GuestBufferMemory.cpp:4214) opens and parses all of/proc/self/mapson every label into unregistered memory, andUnregisteredHostImportcreates a new host-pointer import (vkAllocateMemory+vkCreateBuffer) for each one. Both happen insideWriteLabelOnGpu, under the GPU mutex, at least once per PS4 flip. A relinked title can have thousands of mappings. Consider caching the import per page (or the checked range), keyed by the mapping, or show in a trace that the cost is negligible.Perf evidence. I agree with MarcZX10's earlier point and have nothing new to add. The measurements come from an unpublished local stack on another base, and the body says they predate the follow-ups, which may bring back part of the removed waits. The second pair's traces are announced as "will be attached by hand", but I don't see them on the PR. CONTRIBUTING asks for both traces.
Not verified
9c6d153decbase. I only built and tested the resolved merge into currentmain.main-only run of the focused tests. The merged-tree log has zeroVUID-lines, so the change adds none on this GPU.main. I used the PR's own switches instead (see above).main.To get this to a good state
mainand resolve the two conflicts.agc_driver_queued_constant_ram_dumpabort on Linux. Report an ASan or malloc-debug run of that test.VideoOutDriver::Openwaits for the previous config's outstanding GPU work before replacing it. Add a close/reopen regression test with a label store in flight.mainand on the change, and update the Tested section.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T06:52:20Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
This pull request does not merge cleanly into
main(d1ae628bc2): heada814af06eeconflicts incore/libs/prx/libSceAgcDriver/Execution/src/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_recorder_tests.cmakePlease rebase it onto current
main. I will review the change once it merges cleanly.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T07:51:17Z.
Review: APPROVED
Re-checked — approved
The three blocking findings from my last review are resolved: heap corruption, conflicts with
main, and the VideoOut use-after-free. The new commits are the retired-item clears (0bc7829562), the wait in VideoOutOpen(70d8cce27d),PROCMAP_QUERY(4647d9c464), the variant-validation recapture (b8c3f25cdf) and merges ofmainup tod1ae628bc2. They build and pass here, and the negative controls for the new and changed tests fail as expected.What changed since my last review
Since
0a08a3b019:0bc7829562empties the thread-local reclaim vectors beforeEnqueuereturns, and addsagc_driver_draw_pipeline_retired_items.70d8cce27d(option B, as the maintainer chose) makesVideoOutDriver::OpencallAgcDriverWaitIdlebefore it replaces a closed port's configuration. It also reworksvideo_out_flip_reopenand adds entries to the debt files.4647d9c464adds aPROCMAP_QUERYioctl path for the Linux page check, falling back to the text parse.b8c3f25cdf:validateVariantreturnsDifferinginstead of draining when only queued stores overlap a cached variant. This answers oneandonlydean's report of 2026-11-03.main, the latestd1ae628bc2. The description and the author's reply were updated to match.What I ran
b8c3f25cdf9de1f0ef2b9300a15964f738a33808,maind1ae628bc2f62459cce1e9872ba5632c938c71f2, merged with--no-ff(no conflicts).PROCMAP_QUERYpath is the one exercised.git diff --checkcheck_conventions.pyAll conventions checks passed.mainVUID-vsmainvideo_out_flip_reopen: no display for a Vulkan window, SDLoffscreen); 0VUID-lines, 0 missing-layer linesagc_driver_queued_constant_ram_dump, 20 repeatsagc_driver11.7 sNegative control
VariantValidation.cpprestored frommain, which removesb8c3f25cdf.agc_driver_queued_constant_ram_dumpthen fails with "a capture after a queued dump drained the draw pipeline 1 times instead of reading the queued bytes". That is the failure oneandonlydean reported.DrawPipeline.cpp, the twoClearOnExitguards were replaced by the oldreclaim.clear()at the start ofEnqueue(a targeted revert: restoring the whole file frommainwould also removeStoredBytes).agc_driver_draw_pipeline_retired_itemsthen fails with "a retired draw pipeline item stayed in the enqueuing thread's storage after Enqueue returned".git status --porcelainis empty.video_out_flip_reopenskips on this machine, so I did not revert the VideoOut wait.Previous findings
agc_driver_queued_constant_ram_dump: Resolved.0bc7829562matches the__call_tls_dtorsbacktrace from my last review.DrawPipeline.cpp:178and:312are covered by a new test that fails without them.main: Resolved. The head merges cleanly intod1ae628bc2. Theneeds rebaselabel looks stale.VideoOutDriver::Open(core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp:411-438) releases the driver mutex and callsAgcDriverWaitIdle(:430). It loops until the same closed configuration is seen twice, so a concurrentOpenis handled.docs/dev/debt/libSceVideoOut.md, and the AGC side indocs/dev/debt/libSceAgcDriver.md.video_out_flip_reopenskips here (no display). Its pass on Windows and its failure without the wait are as the author reports.GuestBufferMemory.cpp:4486-4495usesPROCMAP_QUERYwithquery_flags0, so it asks for the VMA covering the address. It accepts read|write with no shared or exec bit and inode 0, and refuses onENOENT. This matches the text path'srw-p/inode-0 rule.main/change pair on current upstream, and no traces: the author says they were lost.perfmerge is the maintainers' call. Nothing new from me.New findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/VariantValidation.cpp:113-116).QueuedWritesOverreturnsStoredfor any overlap where every queued item is a store, even a partial one.validateVariantthen reportsDifferingwithout looking at the bytes.DispatchLookup.cpp:171-174). The draw-cache statistics then mix them with real content changes.b8c3f25cdfalso changesDispatchLookup's use ofvalidateVariant, but only the draw path is covered, byagc_driver_queued_constant_ram_dump. Consider a dispatch case that reads a queued dump through a cached dispatch variant.Not verified
video_out_flip_reopenon this machine (it skips: no display for a Vulkan window). Its result is author-reported (Windows, AMD).PROCMAP_QUERYfallback text path. This kernel has the ioctl.