feat(agc): write RELEASE_MEM DATA_SEL 4 for PS4 guests as an 800 MHz count #9893
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9893"
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:33Z.
What
Get-fix/AnyPS5#19, moved upstream as Get-fix asked. #9431 is on
mainnow, so this PR's diff is only the change below.PS4 titles write the GPU's 64-bit counter with
EVENT_WRITE_EOPandDATA_SEL = 4, and #6977's libSceGnmDriver lowers that packet to aRELEASE_MEMwith the same selector.main(#7911) throws forDATA_SEL = 4because the PS5 counter is not known. Gang Beasts and the Hasbro Family Fun Pack (CUSA03312) both write it, and the Hasbro bring-up has been running on a local 100 MHz stand-in.ntamas94 measured the counter on a PS4 Pro in base mode (FW 10.71), with the packets Gang Beasts writes, timed against the TSC over 124 s:
DATA_SEL = 4advances at 798.017 MHz of console time. That is 0.25% under the 800 MHz thatsceGnmGetGpuCoreClockFrequency()reports and that Gang Beasts divides by.This PR applies that rule:
ShaderRecompiler::GcnGuestShaders()),RELEASE_MEMwithDATA_SEL = 4writes an 800 MHz count of the host's steady clock. The count starts at zero when libSceAgcDriver loads. It is written wherever the driver resolves the packet: on execution, as a deferred label (DecodeLabelWrite), and as a run-time store inDecodeStores.DATA_SEL = 4still throws "RELEASE_MEM of the 64-bit system counter (DATA_SEL 4) is not implemented", as #7911 does onmain.DATA_SEL = 5still throws as GDS data, and 6 and 7 still throw as reserved.DATA_SEL = 3value moved into the same helper (ReleaseMemValue) unchanged.What it does not do, recorded in
docs/dev/debt/libSceAgcDriver.md:main's libSceGnmDriverForNeoMode reports 911 MHz fromsceGnmGetGpuCoreClockFrequency, so in Neo mode the two values differ.DATA_SEL = 3to be the TSC divided by 16, a 40-bit count. The driver still writes 100 MHz of the host's steady clock for it.#6977's libSceGnmDriver does not export
sceGnmGetGpuCoreClockFrequency, so on that path there is no second value to keep in step with.shadPS4 names the selector
PerfCounterand writes the TSC scaled to the GPU core clock.Nothing in it depends on the title.
Tested
Windows 11 Pro 26300, WinLibs GCC 15.2.0, Release, AMD Radeon RX 9070 XT (driver 32.0.31041.1004),
ANYPS5_GPU=AMD.Base. This branch is now
5c52198a02, which ismain5b913d40c6merged in, plus a debt-entry commit. Every file #9431 touched takesmain's version.git diff 5b913d40c6 5c52198a02holds three files:Execution/src/Pm4.cpp,tests/Pm4.cppand the RELEASE_MEM debt entry.git merge-treewithmainfae9e483bb, 19 commits later, has no conflicts; that merge was not built.agc_driver_pm4hastestGcnReleaseMemSystemCounter. With GCN shaders on, twoRELEASE_MEMpackets are executed 20 ms apart, and the test checks three things:Revert checks on
5c52198a02, one rebuild each;agc_driver_pm4fails every time and passes again with the file restored:Execution/src/Pm4.cpp, as on5b913d40c6DecodeLabelWriteaccepting 4DecodeStorestreating 4 as run-timeValidation layer: run with
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -V, onmain5b913d40c6and on this branch. The 58 tests:agc_driver_pm4,agc_driver_pm4_replay,agc_driver,agc_driver_graphics,agc_driver_register_key,agc_driver_gcn_detileandagc_driver_pattern_buffer_fillagc_driver_flipand the 17video_out_flip_*modesagc_gcn_decode,texture_format_lookup,agc_driver_resource_cache_replaced_textureandagc_depth_copy_kept_bytesagc_driver_depth_*testsResults:
main: 58 of 58 pass.VUID-line orwas not found but was requested by env var VK_INSTANCE_LAYERS. All 49Selected GPUlines in each log name the RX 9070 XT. The PM4 tests themselves create no Vulkan device, so the layer says nothing about them.Linux: WSL Ubuntu, g++ 15.2.0, cmake 4.2.3, Unix Makefiles,
-j4, from agit archiveof this code on the Linux filesystem.CMakeLists.txt:513and:521, because the machine has no X11 or audio development packages. In that local copy only, those twoFATAL_ERRORs became warnings. FFmpeg came from the project'sffmpeg-linux-x64.zipthroughFFMPEG_PREBUILT_DIR.shader_recompiler_agc_driver,agc_driver_pm4_testsandagc_driver_graphics_tests, and so all oflibSceAgcDriver. That includesGraphics/src/PipelineJournal.cppandcore/shader/recompiler/ShaderDiskCache.cpp, with their__linux__ && __x86_64__ && __GLIBCXX__size guards active.agc_driver_pm4andagc_driver_graphics, 2 of 2 pass. NoSelected GPUline: no GPU ran there.CUSA03312: the Hasbro titles ran on
ps4/limbo-gpuat93eeee0141(#6977's head then) on a local 100 MHz stand-in for this until Get-fix/AnyPS5#19. Not rerun on this base: the titles also need #9432.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branch feat/gcn-release-mem-perf-counter, againstmainfae9e483bb:GuestMemory::WritebesideReleaseMemValueinExecute. The two compose, and whichever lands second resolves it.mainthemselves, so the tool could not compare them. All share the debt file or one of the twoPm4.cppfiles: #6188, #6549 and #10249 changeExecution/src/Pm4.cpp, and #6185, #6186 and #6549 changetests/Pm4.cpp.Merge of
main4180951e90, 5 Nov. Heada87d435d96. A clean merge to rerun CI. Onbe678bc388, thewindowsjob stopped compilingGraphics/src/DepthSurface.cpp:1623("cannot convert 'VkMemoryAllocateInfo' to 'const VkImageCreateInfo&'"). That file isn't in this PR: the error came frommainof that hour, where #15301's call and #15855's newallocatesignature met.main4180951e90compiles it.agc_driver_pm4,agc_driver_pm4_replay,agc_driver_pm4_replay_toolandagc_driver_graphicspass, 4 of 4, in one run. They run on the mock device, so no Vulkan device is selected.check_conventions.pypasses.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:33:54Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The RELEASE_MEM
DATA_SEL = 4change itself works and its test catches the old behaviour, but the branch conflicts with currentmainand, without any merge, does not compile on Linux x86_64 with GCC/libstdc++; both problems come from the #9431 content the branch carries.What I ran
781ffafe9f9fc04d5a6758d7de785dbd25518536main:b433c40f2f46aa2e59e19806010a839ac8572d64Results
mainb433c40f2fGraphics/include/State.hppandGraphics/src/State.cppgit diff --checktools/check_conventions.py --base origin/mainstatic_asserts inPipelineJournal.cppagc_driver_pm4*(16 tests), head with the asserts relaxed locallyagc_driver_pm4*(16 tests),mainagc_driver_pm4repeated 20 times (timing test)VUID-lines /was not found but was requested by env var VK_INSTANCE_LAYERSMerge conflicts
State.hpp:mainaddedhullWaveSizeandtessellationGeometrytoShaderStageswhere the branch addslegacyVertex, and changedDrawKeyRegisters(still 50 entries,0x002now 2 words) where the branch grows it to 52.State.cpp:decodeDepthPlane's extent and mip checks, andDecodeShaderStages, wheremainadded the tessellation-plus-geometry path.Build failure at the head
Negative control output
Negative control
I restored only
core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cppto the branch's base merge4e8243ac48(mainplus #9431;main's ownPm4.cppcannot be paired with this tree) and rebuilt with the asserts relaxed.agc_driver_pm4then fails intestGcnReleaseMemSystemCounterwith "RELEASE_MEM of the 64-bit system counter (DATA_SEL 4) is not implemented", as the description says. With the PR's file back it passes.Findings
Blocking
PipelineJournal.cpp:40-45assertssizeof(State) == 840andsizeof(ShaderStages) == 112. Thebool legacyVertexthat #9431 adds atState.hpp:35makes them 848 and 116. This confirms the earlier comment that reported the same error after merging a newermain, and adds two details. First, it fails on the pushed head itself, with no merge: the asserts are already inmain07da04f947, which the branch is built on. Second, they sit behind#if defined(__linux__) && defined(__x86_64__) && defined(__GLIBCXX__), which is why the Windows/MinGW runs in the description and the comments all built. The asserts guard the pipeline recipe codec.legacyVertexis not written by the encoder (PipelineJournal.cpp:175-179) or copied into the canonical state (PipelineJournal.cpp:1483-1487). Fix: in #9431, either encode and canonicalizelegacyVertexor show it cannot affect a created pipeline, then update both sizes. Re-merge that into this branch.maininGraphics/include/State.hppandGraphics/src/State.cpp(details above). Both files come from #9431, not from this PR's own commits. The PR already carries the "needs rebase" label. Fix: resolve in the #9431 merge (Get-fix/AnyPS5#22) against currentmainand merge it again here. TheShaderStageshunk overlaps finding 1, becausemainnow addshullWaveSizeandtessellationGeometrytoo.Non-blocking
PacketMemory.cpp:78-88),DecodeLabelWritecomputes the bytes, includingReleaseMemValue's timestamp, when the queue worker reaches the packet. They are stored and written to guest memory only after the GPU work completes. A title that takes the difference of two EOP counter writes to time GPU work will see queue-processing time, not GPU time.DATA_SEL = 3already behaves this way, so this is not new. Because the PR exists for titles that read this counter, consider adding it to the RELEASE_MEM debt entry, or sampling the clock when the deferred label is flushed.libSceAgcDriver.md:28) keeps the amdgpunvd.hlink ontorvalds/linuxblob/master. Since the line is being rewritten anyway, a tag or commit link would keep the citation stable.The PR's own change in
Pm4.cpp:47-56and theValidategate at line 489 hold up:DATA_SEL = 5, 6 and 7 still throw.DecodeStoresreports 3 and 4 as run-time stores.Submission.cppalready excludesDATA_SEL >= 3from known writes.duration_castto 800 MHz ticks is exact integerns * 4 / 5inuint64_t.Not verified
libSceAgcDriverand the PM4 tests; that does not show the journal stays correct withlegacyVertex.To get this to a good state
main, resolveState.hppandState.cpp, and update thePipelineJournal.cppcodec, canonical state and size asserts for the newShaderStagesfield(s). Check on Linux x86_64 with GCC, where the asserts are active.agc_driver_pm4.Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T23:49:39Z.
Review: APPROVED
Reviewed on Windows: approve
The diff against
mainis now only theDATA_SEL = 4change:Pm4.cpp,tests/Pm4.cppand one debt entry. @XairRrR's two blockers came from the #9431 content, and #9431 is onmainnow.What I ran
Head
5c52198a02merged onto currentmain(clean merge). Windows 11, WinLibs GCC 15.2.0, Release,BUILD_TESTING=ON.ctest -R '^agc_driver_pm4'main'sExecution/src/Pm4.cpprestoredagc_driver_pm4fails with "RELEASE_MEM of the 64-bit system counter (DATA_SEL 4) is not implemented"XairRrR's findings at
781ffafe9fPipelineJournal.cppstatic_assert on Linux/libstdc++) and Blocking 2 (conflicts inState.hppandState.cpp) were in the #9431 files. The PR's diff no longer touches them. The NVIDIA CI run on5c52198built the merge on Ubuntu and reports 0 new failures. I didn't build on Linux myself.docs/dev/debt/libSceAgcDriver.md:34now records decode-time sampling and its effect on two deferred labels (5c52198a02).nvd.hlink now points at tagv6.18, lines 379-380 ("3 - send 64bit GPU counter value", "4 - send 64bit sys counter value"). The entry is 997 characters.Code
Validatestill throws for a PS5 guest'sDATA_SEL = 4(tests/Pm4.cpp:1194), and for 5, 6 and 7.testGcnReleaseMemSystemCounterchecks the 800 MHz rate between two bracketed reads, the 8-byte label, and the run-time store fromDecodeStores.ReleaseMemValuekeepsDATA_SEL = 3as before.Not run: CUSA03312 or any title, and macOS.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T05:44:05Z.
Review: APPROVED
Re-checked — approved
main5b913d40c6is now merged into the branch, so the #9431 content is gone and the diff is only the GCNRELEASE_MEMDATA_SEL = 4counter. A debt-entry commit (5c52198a02) records decode-time sampling, pins thenvd.hlink and notes the Neo-mode 911 MHz mismatch. The merged tree builds on Linux/GCC and the PR's test passes. Withmain'sPm4.cpprestored, the test fails.What changed since my last review
05c9c4200cmergesmain5b913d40c6, which already contains #9431. The diff againstmainnow covers 3 files (+45 −11):Execution/src/Pm4.cpp,tests/Pm4.cppand the RELEASE_MEM entry indocs/dev/debt/libSceAgcDriver.md.5c52198a02rewrites that debt entry:DATA_SEL3 and 4 are sampled when the packet is decoded;v6.18;sceGnmGetGpuCoreClockFrequencyin libSceGnmDriverForNeoMode reports 911 MHz while the count stays at 800 MHz;What I ran
Head
5c52198a0291798daa362fd4a0cf94881d37c39c,main5cb015caaaaf83f8ee431414ee6a457b5b307d49, merged tree2eeead1b0efb74eb5d316ca404740533d94baf15. Debian 13 VM (Xeon Gold 6136, AVX2/FMA), GCC 14.2.0, Release, Ninja, lavapipe (Mesa 26.1.6, LLVM 19).The script also built the whole merged tree (configure, build and
libsall OK) and ran the 2167 tests the change can reach, with a Khronos validation comparison over 759 tests.git diff --checkcheck_conventions.pyPipelineJournal.cppasserts active)agc_driver_pm4*(16 tests), 5 repeatsmain, 2 failures listed as new (both come frommain, see below)VUID-line compared withmainThere are two "new" failures,
agc_driver_image_sample_lod_clamp_shader_laneandunwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group. Neither is caused by this PR:096c45570f, 227 commits behindmain.Pm4.cpp) restored tomain, with the same message (image_sample_lz ... thread 0 component 1 is 0.000000, expected 0.062500).Negative control
I restored only
Execution/src/Pm4.cppfrommainand rebuilt.agc_driver_pm4then fails withRELEASE_MEM of the 64-bit system counter (DATA_SEL 4) is not implemented, which istestGcnReleaseMemSystemCounter. With the merged file back, all 16agc_driver_pm4*tests pass five times in a row. The worktree is back to the merged tree. The author's per-piece revert checks (label decode, run-time store, rate, epoch) are accepted as author-reported; I did not repeat them.Negative control output
Previous findings
PipelineJournal.cppstatic_assert on Linux/libstdc++: Resolved. The PR no longer touchesState/ShaderStages. The merged tree builds here with GCC 14.2 on x86_64 Linux, where the size guards are active.State.hpp/State.cpp: Resolved. The PR no longer changes those files, and the script merged it intomain5cb015caaawithout conflicts.nvd.hlink onmaster: Resolved. The link now points at tagv6.18, lines 379–380. I could not open it with no network.New findings
Blocking
None.
Non-blocking
None. I re-read the code at the head:
Validategate atPm4.cpp:491still throws for a PS5 guest'sDATA_SEL = 4, and for 5, 6 and 7;ReleaseMemValue(Pm4.cpp:51) serves both the label path (:632) and the execute path (:1142);DecodeStores'>= 3only ever sees 3 or 4, becauseDecodeLabelWritereturnsnulloptabove 4.Not verified
nvd.hv6.18 line numbers and the ntamas94 measurement link: no network here.