fix(agc): stop resolveGroupAhead on unknown writes and reopen gate after HLE #11439
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11439"
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 hamb3r on 2026-10-26T13:27:43Z.
What
When
Driver::resolveGroupAheadscans a compute command buffer ahead of an in-flightWAIT_REG_MEMgate, it captures SRT/BDA memory for upcoming dispatches so their shaders and resources are ready before the gate opens. Four issues in the ahead-resolution path caused it to either capture stale pre-write descriptors across earlier GPU writes, pollute the globaldispatchCachewith rejected captures, or stop ahead resolution prematurely:FaultBuffer-only shaders bounded inDispatchWriteRanges(WrittenBuffers.cpp):DispatchWriteRangestreatedbinding.kind == BufferBindingKind::FaultBufferthe same asGdsandBdaPagetable(bounded = false). However,FaultBufferis an internal fault-reporting buffer added by the recompiler to specialized descriptor-indexed atomic shaders and does not write to arbitrary guest memory addresses. TreatingFaultBufferas bounded (unlessGdsorBdaPagetableis present) prevents specialized compute shaders from prematurely terminating ahead group resolution.resolvingAhead(), record unvalued GPU copies, and reopengateOpened()after HLE (Dispatch.cpp,BufferCopy.cpp):resolvingAhead(),tryDwordPatternFillBuffer,tryConstantDwordFillBuffer,tryClampedGlobalFillBuffer, andtryMemoryValueFillBufferwere bypassed (!resolvingAhead()), causing buffer-fill dispatches to be captured as regular compute shaders instead of stopping ahead resolution at the HLE fill boundary.resolvedAhead()was empty,closeGate()closed the ahead gate without reopening it for the dispatches that follow the HLE operation in the same group; reopeningopenGate()whenresolvedAhead_.empty()allows subsequent dispatches in the submission to be resolved ahead against the updated post-HLE state.Driver::noteCopyWriter, GPU-backed HLE copies (!cpuDone) that did not populateknownCopyValues(e.g., when the source range had a pending GPU write) only calledrecorder->notePendingWritewithout recording a writer inwrittenBuffers, soDispatchWriteRangesandpendingWritetreated the destination as having no writer. RecordingwrittenBuffers->noteWrite(destination, size, 0)marks the destination under foreign writer policy (program == 0).Driver::resolveGroupAheadon unknown writes and deferdispatchCacheinsertion (Driver.hpp,Dispatch.cpp,DispatchAhead.cpp):Driver::resolveGroupAheadfromWrittenBufferRanges(which only inspects direct SRTV#buffers and misses BDA table buffers,StorageImagewrites, and unbounded flags) toDispatchWriteRanges. When a dispatch is not resolved orDispatchWriteRangesreports!bounded,resolveGroupAheadincrementsstats.unknownWritesand breaks immediately (break;) instead of continuing to capture later dispatches that may depend on the unknown write.bool cacheInserted = falsetoDriver::CaptureResultand deferredinsertDispatchduringresolvingAhead()untilresolveGroupAheadverifies!OverlapsLabeland!OverlapsRange, preventing rejected ahead captures from polluting the globaldispatchCachewith stale pre-write snapshots.WriteDataWrittenAhead.cpp):agc_driver_write_data_written_aheadto verify that rejected ahead captures do not insert intodispatchCache, that CPU-backed and GPU-backed HLEStreamCopy,FillKernel, andDwordPatternFillupdate descriptors before subsequent direct andIndirectGpudispatches, and thatStorageImagewrite overlap and unboundedGdswrites stop ahead resolution cleanly.Tested
ctest --test-dir build-portable -R "^(agc_shader_table_snapshot_reuse|agc_shader_table_snapshot_reuse_unmasked|agc_shader_type_zero_image_materialization|agc_shader_memory|agc_shader_result_memo_budget|agc_shader_result_memo_budget_threads|agc_shader_result_memo_budget_masked|agc_driver_constant_dword_fill|agc_driver_dispatch_ahead_adopt_check|agc_driver_gated_dispatch_capture|agc_driver_gpu_indirect_arguments_written_ahead|agc_driver_indirect_arguments_written_ahead|agc_driver_pipelined_dispatch|agc_driver_stream_copy|agc_driver_write_data_written_ahead|agc_driver_write_data_written_ahead_draw_pipeline|agc_driver_gated_dispatch_capture_draw_pipeline|agc_driver_gated_dispatch_capture_short_timeout|agc_driver_pipelined_dispatch_item)$" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationon bothmain(08a10d225306) and this branch (cb5d7fe3ef74) — all 19 tests pass, neither log containswas not found but was requested by env var VK_INSTANCE_LAYERS, and 0VUID-validation errors are logged.agc_driver_write_data_written_aheadfail deterministically onmain(rejected ahead capture polluted global dispatchCache with an extra insertandHLE StreamCopy (CPU-backed): dispatches after descriptor update used stale descriptor (stale 2, fresh 0)) and pass on this branch (Fresh[0] == 2..3, Stale[0] == 0).PPSA01341(Demon's Souls v1.07): verified thatDriver::resolveGroupAheadno longer captures stale pre-copy/pre-fill descriptors (fixingVUID-vkCmdCopyBuffer-size-00115and intermittentEXCEPTION_ACCESS_VIOLATIONcrashes inINTRO), stops on unknown writes, and reopens ahead resolution after HLE copies/fills.Before (
main):After (this PR):
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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T13:40:03Z.
Review: CHANGES_REQUESTED
Reviewed the rebased head
c53c696e97cb7b27c12081f9c28f877689b18160against currentmainbf77a9e9cba4b02c358779b35295176dd9cae164. The code changes are consistent with the stated ahead-capture safeguards, and I found no additional functional defect in the inspected hunks. However, the PR’s reported 15-test Vulkan comparison usesmainacb900c19432and the prior PR headdd3a169b5682. Currentmainincludesaccae4b62d, which changes dispatch adoption andDispatchAhead.cppin the same paths this PR modifies; the hosted product jobs are skipped. Please rerun the documented focused tests on currentmainand this rebased head with the stated Vulkan validation settings, compare the logs for newVUID-errors, and update the report before requesting approval.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T14:07:59Z.
Review: CHANGES_REQUESTED
The new head and test report address my earlier request: the PR now tests against
mainat9656d366be90and reports all 16 focused Vulkan tests passing on bothmainand the change, with no missing-layer messages orVUID-output. I have not independently reproduced the Windows/NVIDIA run.One merge-order item remains. I ran a three-way comparison with open #8105 from their common base; it has a content conflict in
Dispatch.cppat the declaration afterhtileClearCompletion: this PR addscodeSpanand #8105 addsGraphics::HtileMaskClear htileMask. CONTRIBUTING.md requires authors to agree on order and declare it withDepends on. Please coordinate with #8105's author and update this PR before merge. I manually checked #7201'sDispatch.cpphunk (NoteRecentWorknear the function start); it is separate from this conflict.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T15:11:36Z.
Review: CHANGES_REQUESTED
I rechecked head
0f8b37f008e3e58d3d0307f353caf2c59481f79d. The previousDispatch.cppoverlap with #8105 is resolved: I confirmed the merge-tree is clean in both merge orders. The hosted conventions, eligibility and report checks pass; AGC product jobs are skipped by path policy.Two follow-ups remain before approval:
git diff --check upstream/main...upstream/pr-11439reports a new blank line at EOF incore/libs/prx/libSceAgcDriver/tests/execution/WriteDataWrittenAhead.cpp:408.9656d366be90, while currentmainis7903201bb426. I found no intervening changes to this PR's touched source/test paths, but CONTRIBUTING requires branches to stay current. Please sync to currentmainand rerun the documented focused Vulkan-validation comparison on the same GPU, including the no-missing-layer and no-new-VUID-checks.I did not independently run the Windows/NVIDIA suite. The previous dependency-order finding is withdrawn because the current heads merge cleanly in either order.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T10:17:36Z.
Review: COMMENTED
First NVIDIA run on Linux for this head
fb6613fa5.Linux run: Ubuntu 26.04, GCC 15.2, Release. RTX 3070 (NVIDIA 595.99.02) and lavapipe (Mesa 26.0.3), one at a time via
VK_DRIVER_FILES. Khronos validation layer 1.4.341 withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1;VK_LOADER_DEBUG=layershows the layer inserted, no "was not found but was requested", 0VUID-lines.Base
main808a557ac; the merge is clean.main+ only this PR'sWriteDataWrittenAhead.cpp:agc_driver_write_data_written_aheadand_draw_pipelinefail on both devices withnormal dispatch after rejected ahead capture received the rejected stale variant from global dispatchCache (stale 3, fresh 0).agc_shader_result_memo_budget*tests. 0VUID-.^agcsuite (no flip/display/lds64,-j1): 3070 1052/1052, lavapipe 1051/1052. The one failure isagc_driver_multisample_retirement, which also fails onmain. Onmain,agc_submit_progress_no_timelinefailed once on the 3070. The GPU was shared, and that test passed with this PR.public_headerspasses.GPUs tested: NVIDIA RTX 3070 (Linux), lavapipe.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T10:55:48Z.
Review: CHANGES_REQUESTED
Re-check — changes requested for current-main integration\n\nThe author’s 19/19 focused Vulkan-validation result on both
mainand the PR head addresses the previous test-evidence request. The validation-layer load and zero-VUIDreporting are also documented.\n\nThe comparison now usesmain1b580f13cf, while current upstreammainisd2b15d8802. Since that base,core/libs/prx/libSceAgcDriver/CMakeLists.txtanddocs/dev/debt/libSceAgcDriver.mdchanged, along with related AGC tests. The merge preview against current main is clean, and I independently confirmedgit diff --checkandcheck_conventions.pypass. CONTRIBUTING requires the branch to stay current; please refresh ontod2b15d8802and rerun the focused comparison on the merge-ready head so the updated registration and debt context are covered.\n\nI did not run the Vulkan tests locally; product GPU checks are path-skipped by hosted CI.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T21:18:42Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes requested
The branch now merges current
main, but the focused Vulkan comparison still covers the prior integration, including three source files changed by the new base.What I ran
Reviewed exact head
5cc2975a20f7beb519a072fa14a34e60999be417, whose second parent is currentmain9624d8c6bb9e96b7aa92b815f55690f69b0a88d5. I compared the tested main1b580f13cf7ewith current main and inspected the overlap inDriver.hpp,BufferCopy.cpp, andWrittenBuffers.cpp. Environment: Linux x86-64, Git and GitHub CLI; no build or GPU test was run locally.Results
mainis the merge commit's second parentDriver.hpp,BufferCopy.cpp, andWrittenBuffers.cppchanged on main; those are also modified by this PR1b580f13cf7eand headc4ddc2d40465; this is before the current-main merge and does not cover the three overlapping main updatesUnedited local command output
Findings
Blocking
WrittenBufferIndexstorage and writer-recording paths in files this PR modifies. The previous 19-test comparison used main1b580f13cf7eand headc4ddc2d40465, so it does not validate the combined behavior now submitted at5cc2975a20f7. Please rerun the focused Vulkan suite and the relevant negative controls on current main9624d8c6bb9eand this exact merged head, with validation-layer load andVUIDresults recorded.I found no additional source-level defect in the rechecked diff.
Sources
Not verified
I did not build or run the current merged head locally or on a GPU. The exact-head Windows job was still running; conventions and labels were queued. Linux product and specialized jobs were skipped.
To get this to a good state
Rerun the same 19 focused tests and issue-specific negative controls against current
mainand exact head5cc2975a20f7, recording the required Vulkan layer andVUIDchecks. I will recheck the resulting head and hosted statuses.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T21:51:54Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes requested
The exact-head regression evidence and current-base merge are satisfactory, but the branch conflicts with two open PRs and its dependency checklist still says
none.What I ran
0711645eef72b5e26934a6245c417bfe52bd5b2f.upstream/mainatd820fef1827f27247cd28da7b4eec7891904bae5; the merge preview was clean (99eca890510413d8115e076ea406fec1aa377cba). No files touched by this PR changed onmainafter the tested basec40cef843681.Results
99eca890510413d8115e076ea406fec1aa377cba.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp.Dispatch.cpp. Both PRs remain open; #12657's description says it depends on #12147.mainc40cef843681and this head, with the validation layer loaded and zero VUID errors. This is author-reported; I did not run the GPU tests.Unedited local command output
python tools/check_conventions.py --base upstream/main --head refs/review/pr-11439-headgit merge-tree --write-tree upstream/main refs/review/pr-11439-headgit diff --check upstream/main...refs/review/pr-11439-headexited 0 and produced no output.Both pairwise merge previews exited 1 and reported:
Findings
Blocking
Dispatch.cppwith open #12147 and #12657. The PR currently listsDepends on: none.CONTRIBUTING.mdrequires authors to agree on which overlapping PR goes first and declare that order withDepends on(pinned contribution rule). Please coordinate the order with the affected authors and update the dependency line; then I can recheck the combined merge.Non-blocking
Not verified
To get this to a good state
Please record the agreed order for the overlapping PRs in
Depends on. I will rerun the merge checks and review the updated head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T04:23:29Z.
Review: APPROVED
Re-checked — new head, looks good
The update preserves the unrelated prebuild block, and I confirmed the branch combines cleanly with current main and both cited PRs in either merge order.
What I ran
Reviewed head
cb5d7fe3ef741780004cfd8e4e677d1b033e7311against current main5ecef095b61e7a406b279c97896f3a8a6fbd6353; current-main merge tree is907b51b66dc5a7a17e45994202854189394b9941.Results
Not verified
I did not run a local build or Vulkan tests. Product Linux and specialized hosted checks were skipped for this change.