fix(agc): make pooled depth-only recording safe to execute, retain and fail #27979
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27979"
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 chitters2004 on 2026-11-28T00:09:36Z.
What
#19697 records depth-only draws into secondary command buffers on the recording pool, behind
APS5_PARALLEL_ATLAS(off by default). This PR fixes five bugs in that path. There is one commit per bug, and each commit carries the test that fails without it.The primary kept its cached state after executing a secondary. After
vkCmdExecuteCommandsthe primary's bound pipeline and dynamic state are undefined.CommandState::ExecuteCommandsstill kept its cache. So an inline draw, then a pooled draw, then the same inline draw skipped the pipeline bind and every dynamic state, and the second inline draw ran on undefined state.ExecuteCommandsnow invalidates the cache.CommandStatecaches only the graphics pipeline and the dynamic state. Descriptor sets, vertex and index buffers and push constants are recorded again on every draw, and no compute binding is cached, so oneInvalidate()covers all of it.The secondary was retained after its execution was recorded.
recordDrawrecorded the execute first and then calledKeep(result.release). If theKeepvector insert threw, the release token handed the secondary back to its worker while the primary still referenced it. The newRecorder::ExecuteSecondaryretains the release token first, then records the execute (which also invalidates, as in 1). A failed retain now leaves nothing executed, and the token returns the buffer at once. The test checks that the token is alive while the execute is recorded, stays alive after the batch is submitted, and is released once the recorder has finished.The pooled body reached the recorder from a pool worker. The producer holds
GuestMemory::GpuMutexand blocks inTake()while a worker records the body, but the body still used the recorder and the shared draw state:Keeps its pipelines, which goes throughensureOpen()(this aborts underAPS5_ASSERT_GPU_LOCK);BindDrawUseruns the guest-buffer check, which can publish depth through the recorder, andprepareFaultSlot, which notes the open serial and updates the fault descriptors;recordDrawCommandscallsNoteSampledDrawandNoteGuestWork;recordDrawCommandsinserts the trace token into the open batch and logs its serial.The pooled body now records only into its secondary and touches no
Recorder:ShaderResources::PrepareDrawUse) before recording on either path;RecordDrawUse;BindDrawUseremains for the other caller);NoteSampledDrawandNoteGuestWorkafterTake(), so a pooled guest draw now marks its batch as guest work as an inline one does (Recorder::OpenGuestWorkForTestlets a test read that mark);ParallelAtlasEnabled().NoteSampledDrawandNoteGuestWorknow assert the GPU lock underAPS5_ASSERT_GPU_LOCK, like the recorder's other entry points (Keepalready did, throughensureOpen()). Excluding stencil replay from the pool would not have fixed this, because every pooled draw runsBindDrawUse.A pooled draw that failed left its rendering open. The producer began rendering before the worker recorded the secondary, and the recorder learned the pass was open only after the execute. A worker failure, a failed
vkEndCommandBufferor a failed retain then leftvkCmdBeginRenderingin the primary with nothing to end it.recordPassOpenis now split in two.recordPassSetuprecords what the pass needs before it opens (attachment proxy loads, barriers, the pixel function LDS preparation, sample reordering, staged clears) and still runs before the worker is dispatched, so everything the body binds, such as the LDS descriptor set, exists before the worker records.recordPassOpenonly begins (or continues) the rendering, and it now runs afterTake(), once the secondary is recorded (it inherits its formats, so it does not need an open pass). A failed retain ends the rendering it began before the error leaves the draw. Indirect, mesh-indirect and captured draws, whose pass setup computes the body's argument buffers, are not pooled.Two noexcept paths allocated. A secondary's release token returns its buffer to the worker from a destructor, and the worker publishes its result outside its
catch; both allocated (buffers.push_backandready.emplace), so a failed allocation there terminated the process. The worker now reserves the return list's capacity before it allocates each new command buffer, andOrderedAssembly::Reservecreates the result's slot, soSubmitonly fills it and isnoexcept.Sites on main
7e3053f522:Graphics/src/Recorder.cpp:1677(ExecuteCommands);Graphics/src/Draw.cpp:3384-3385(execute, then keep);Draw.cpp:3358(stencil replayKeepin the pooled body);Draw.cpp:3332andGraphics/src/ShaderResources.cpp:7579(BindDrawUsein the pooled body);Draw.cpp:3370(rendering begun beforepool.Recordat 3376);Graphics/src/RecordingPool.cpp:41and:149(returns that allocate) and:154(publish outside thecatch);Graphics/include/OrderedAssembly.hpp:20(ready.emplace).When
APS5_PARALLEL_ATLASis off, the inline path runs the same operations as before. Two moved earlier: the draw's resource preparation and the stencil replay pipelineKeeps now run before the pass opens instead of inside it. Neither takes the command buffer (the preparation checks the guest buffers and fills the fault slot, andKeepholds a reference), so the draw records the same commands in the same order. It gains one null check perrecordDrawCommandsand the two lock asserts. WithAPS5_ASSERT_GPU_LOCKunset, an assert costs 1.3-1.8 ns per call (5 rounds of 10^8 calls through the library export on a Ryzen 7 5800X; a microbench, not a timed game run), so about 3 ns per draw.Also adds
agc_driver_depth_plane_sampling_parallel_atlas, which runs the depth-plane sampling tests withAPS5_PARALLEL_ATLAS=1. No test set the switch before.Thanks to @Logan1h for #19697.
Tested
Windows 11, NVIDIA GeForce RTX 3080, driver 621.40 (Vulkan 1.4.357).
Red on the parent of each fix (or the named mutant), with that fix's test:
agc_graphics_state_recorderfails with "the same draw after executing a secondary command buffer: recorded but expected [bind 0 0][viewport ...]..." (nothing re-recorded).ExecuteSecondaryswapped (execute, then retain; the injected failure sits inside the retain, so it moves with it), fails with "a secondary command buffer that could not be retained was executed: recorded [execute 1]".agc_driver_stencil_replay_parallel_atlas(--pooled,APS5_ASSERT_GPU_LOCK=1) aborts with "[lock] ASSERT: Recorder::Commands reached without GuestMemory::GpuMutex" on the old body, and with "[lock] ASSERT: Recorder::NoteSampledDraw reached without GuestMemory::GpuMutex" when only the notes stay on the worker.agc_driver_stencil_replay_parallel_atlas_tracedfails with "a depth-only draw traced to its batch was recorded on the recording pool". The pooled test then checks the stencil the replay wrote (255 in even columns, 0 in odd).agc_driver_stencil_replay_parallel_atlas_guest_workruns the pooled test with the run report on and checks that the open batch was marked as guest work by the pooled draw and not before it. The check is explicit (--pooled --guest-work) and fails with "the guest-work check ran without the run report" if the report is not running. It fails with "the batch that executed a pooled guest draw was not marked as guest work" when the producer'sNoteGuestWorkInis dropped, and also when the call is made on the worker instead.agc_driver_stencil_replay_parallel_atlas_faultcounts rendering begins and ends. It first injects a failure into the recording callback on the worker (RecordingPool::FailNextRecordingsForTest), expects that exactstd::runtime_error, and requires that no rendering began. It then injects a failed retain, expectsstd::bad_alloc, and requires that rendering began and was ended, followed by a successful pooled draw. On the parent it fails with "a pooled draw that failed left its rendering open"; withvkCmdBeginRenderingmoved back beforepool.Recordit fails with "a pooled draw whose recording failed began rendering".agc_driver_pixel_lds_limit_parallel_atlasmakes a cold-pool depth-only draw whose fragment shader uses buffer-backed function LDS, and checks the LDS values it stored. It skips, with a reason, on drivers that keep pixel function LDS in the shader (no buffer to prepare) or have no graphics pipeline library. WithrecordPassSetupmoved afterTake()it fails with "AGC graphics: pixel function LDS buffer was not prepared"; the same failure came from the earlier version of fix 4, which ran the whole pass open afterTake().agc_recording_pool_allocation_publish,_releaseand_failed-record(a fake device and a failingoperator new) terminate withstd::bad_allocor "terminate called without an active exception".Green with the fixes:
depth_plane|pass_contents|recording_pool|agc_driver_recorder|stencil|graphics_state_recorder|alpha_to_coverage|msaa_dcc|agc_flush_exclusion|agc_map_gate|agc_recorder_|agc_command_memory_reuse|agc_completion_label_wait|pixel_lds, 109/109 passed (the lock-assert tests included). Fork CI run 46083427378 (headc22ff588ce; linux-gate on lavapipe, windows on lavapipe, same test set, against main7e3053f522): nothing fails on the branch that passes on main, and every new test passes exceptagc_driver_pixel_lds_limit_parallel_atlas, which skips on lavapipe ("subgroup size 8 cannot hold a wave32"), asagc_driver_pixel_lds_limitdoes on main; it is covered by the RTX 3080 run above. On Windowsagc_driver_recorderfails on main too.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)AI-assisted: yes
Summary by CodeRabbit
Bug Fixes
Tests
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T00:20:29Z.
Review: COMMENTED
Actionable comments posted: 3
ea100833-5c48-4214-b53a-f86d14b883dfReviewing files that changed from the base of the PR and between
750a5234edandc22ff588ce.core/libs/prx/libSceAgcDriver/Graphics/include/OrderedAssembly.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hppcore/libs/prx/libSceAgcDriver/Graphics/include/RecordingPool.hppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/RecordingPool.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/CommandStateLog.hppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/RecordingPoolAllocation.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_depth_plane_sampling_tests.cmakecore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_pixel_lds_limit_tests.cmakecore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_stencil_replay_tests.cmakecore/libs/prx/libSceAgcDriver/tests/cmake/agc_recording_pool_allocation_tests.cmakecore/libs/prx/libSceAgcDriver/tests/execution/CheckPooledGuestWorkReport.pycore/libs/prx/libSceAgcDriver/tests/execution/PixelLdsLimit.cppcore/libs/prx/libSceAgcDriver/tests/execution/StencilReplay.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T10:08:01Z.
Review: APPROVED
Checked head
7a5cd97539on Windows 11 with WinLibs GCC 15.2 (Release), applied tomainc6331cc61btogether with 13 other open PRs.tools/check_conventions.py --headandtools/debt_fold.py --checkpass, and the full build succeeds.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, and the loader inserted the 1.4.363 layer. It matchesmain: the only failures areagc_driver_linear_target_import_creation, as onmain(fixed in #28029), and on NVIDIA #27972's new NaN row inagc_driver_fp16_overflow_omod. Neither log has aVUID-line.agc_driver_recorder, the fouragc_recording_pool_allocation_*cases,agc_driver_stencil_replaywith its_parallel_atlas,_fault,_guest_workand_tracedvariants,agc_driver_depth_plane_sampling_parallel_atlas,agc_driver_pixel_lds_limitandagc_driver_pixel_lds_limit_parallel_atlas. All runs pass, with the layer inserted and noVUID-line. On the Radeon,agc_driver_pixel_lds_limit_parallel_atlasskips with "the driver keeps pixel function LDS in the shader", as it did on JJenkx's RX 6650 XT. It runs and passes on NVIDIA.mainalso has or that come from load (windows_read_trap_unknown, fixed in #28028, three load timeouts, and aguest_webrtc_threadtiming race in that test).AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T11:28:59Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the author may merge it.
What I ran
Reviewed head
7a5cd97539be21f61f4e5695e28eaf99f97f9210. Read the prepared description, commits, manifest, and diff, then inspected targeted changed code and callers throughrepo_read.py. No build or tests were run in this review; runtime and CI results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read all changed files marked included in the manifest and inspected the excluded
Graphics/src/ShaderResources.cpparound its changed lines throughrepo_read.py. I did not read the excludedtests/Recorder.cppin full; only its relevant additions are visible in the diff. I did not independently run the build, tests, or hardware checks.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T02:10:47Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed the prepared materials for head
f1281ce9f466cde1462d1e0f275188e98e5c3a43. No tests or build commands were run.repo_read.py --helpsucceeded; a pinned source read could not complete because the reader could not write its run log.Results
Negative control
Not run; no tests were executed.
Findings
Blocking
None verified.
Non-blocking
None verified.
Sources
Prepared
description.md,commits.md,manifest.json,files.json, and targeted portions ofdiff.patch.Not verified
The pinned reader did not return repository source context, so the full contents and behavior of changed files were not verified.
files.jsonlists 18 reviewed files and no excluded files; this review did not read all 18 full file texts. Author-reported and CI test results in the PR description were not independently run.To get this to a good state
Nothing is required. Optional: complete the source review with a working pinned reader before making a formal approval decision.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-01T08:16:31Z.
Review: APPROVED
Re-checked head
f1281ce9f4merged into currentmain483b81fb5a, which now has #18185's D16S8 fallback in the same recorder files. The merge is clean. Windows 11, WinLibs GCC 15.2, Release.I ran the tests this PR changes, the whole
agc_driver_recorder, and #18185's D16 depth tests withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer. That is 26 tests with this PR and 16 onmain:mainmainagc_driver_pixel_lds_limit_parallel_atlasskipsThe Radeon skip is the one reported above for the RX 6700 XT: the driver keeps pixel function LDS in the shader. The new depth-only atlas case runs and passes on the NVIDIA card. The loader inserted the 1.4.363 validation layer in every test that opens a device (22 of 26; the four
agc_recording_pool_allocation_*tests open none), and neither log has aVUID-line.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T20:45:56Z.
Review: COMMENTED
The injected retention failure fixture checks balanced rendering for the first pooled draw. The catch deliberately leaves a continued pass open. Could a case inject the failure on a second draw that continues an existing pass, then record a third draw and check both output and balanced begin/end counts? That would verify the continued-pass recovery branch.
Source review at
f1281ce9f4. The head trial-merges onto700fae9438. Paired Vulkan execution is queued.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.