fix(agc): drain queued writes before reading shader callees and call tables #11442
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11442"
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 Sam-mon7 on 2026-10-26T13:32:49Z.
What
ReadRawShaderdrains queue 0 when a queued draw-pipeline item writes the shader code it is about to read. The user-data callees, call-table descriptors and tables thatLinkUserDataCalleeslinks were read without that check.ReadUserDataCalleeandReadGuestBytes(which reads call-table descriptors and tables) now apply the same overlap check and drain first. All three paths use one helper,DrainShaderWrites, which replaces the lambda that was inReadRawShader.Reachability on current
main:InvocationForalready drains queue 0 first, or runs on a thread whereDrawPipeline::Active()is false (traced in the review thread). The new drains do not fire there.LinkUserDataCalleesalso links them (as @Amoenus pointed out). On a draw-cache miss,materializeDrawStagereachesInvocationForon the queue-0 worker while earlier pipelined draws, DMA or fills can still be outstanding, and nothing before it drains the callee or table bytes. So the new drains can fire on that path. GCN mode is enabled only byAgcDriverUseGcnShaders_nid_postfix, and nothing in this tree calls it.maintoday has been demonstrated.agc_driver_queued_shader_callsexercises the linking API directly with an overlapping queued producer that rewrites a callee, a call-table descriptor or a table entry until the drain, and checks the linked invocation against one built after the drain. Its red/green result verifies that ordering contract rather than reproducing a failure through packet execution orDriver::dispatch.Noticed while working on Demon's Souls (PPSA01341) on a local branch; the change is generic.
Tested
Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0, Release, NVIDIA GeForce RTX 4070 (driver 610.88), Khronos validation layer 1.4.363. Merged current
main0d5e03be8cinto the branch as merge commit84c3b32b3a. It had two conflicts:libSceAgcDriver/CMakeLists.txt(the per-test fragment split): resolved withtools/agc_test_split.py resolve. The test keepsANYPS5_NO_SHADER_CACHE=1;APS5_PIPELINED_DRAWS=8andTIMEOUT 30, now intests/cmake/agc_driver_queued_shader_calls_tests.cmake.ReadUserDataCallee: #10140's early return on an unreadable page is kept, with the drain ahead of it.Focused tests,
ctest -R 'agc_driver_(queued|prepared_shader|user_data|callee|call_table|draw_write_ranges|pipelined|gated_dispatch|copied_writer|draw_cache|finisher_label|same_queue_label|unimported_label|write_data_written)' -V -j2withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:main0d5e03be8c: 69/69 pass.84c3b32b3a: 70/70 pass. That is the same tests plusagc_driver_queued_shader_calls.VUID-or a missing-layer message, and no test was skipped.VK_LOADER_DEBUG=layershows the validation layer inserted at instance and device level.Red/green on the new base: with
main'sShaderRegistry.cpp, the new test fails in each case when run one case at a time (shader invocation ignored queued callee write,... descriptor write,... table write). With this change, all three cases pass (Shader calls observed queued code, descriptor and table writes).python tools/check_conventions.py --base upstream/main,python tools/check_test_registration.py buildandgit diff --checkpass on the merged head.Overlap and landing order
The overlap report lists #9899, #10103 and #10140 for
ShaderRegistry.cpp. I checked each against the current heads (git merge-treeand reading the diffs):ReadRawShader. When #10103 lands I'll mergemain, keep its(address, retained)signature and retained-snapshot selection, and replace its localdrainlambda withDrainShaderWritesahead of the cached/retained comparison and the uncached page reads. This is merge order only; neither depends on the other functionally.Depends on, since neither PR relies on the other (#9899 comment). There is a small textual conflict inReadRawShader(itsCheckRangemove next to the removed lambda). It also has one semantic interaction: #9899's link reuse re-reads callee words inLinkUserDataCallees(theunchangedcompare) with a plainGuestMemory::Read. To keep this PR's guarantee, that read needsDrainShaderWrites(address, words.size() * 4)first. Whichever PR lands second adds it in its merge.673fa865f4), before this PR, so its recorded order (this PR first) no longer applies. ItsReadUserDataCalleechange conflicted with this PR and is resolved in84c3b32b3aas described above.#9899 and #10103 merge cleanly with each other and with current
main.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
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T13:44:05Z.
Review: APPROVED
Reviewed head
e7da862d03403e694ffa6a1f8f9d1e19d1a3fb92against currentmainbf77a9e9cba4b02c358779b35295176dd9cae164. The new shared drain preserves the prior raw-shader read behavior and is applied before reading user-data callees, call-table descriptors and table bytes; each range is bounded to the bytes actually read. The regression test holds an overlapping queued producer and checks all three read paths against a post-drain invocation. The test target is picked up by the existing execution-test glob and registered by the shared CMake loop; its timeout/environment properties are set explicitly. The changed paths merge cleanly with current main, andtools/check_conventions.py --base upstream/main --head upstream/pr-11442plusgit diff --check upstream/main...upstream/pr-11442pass.The PR reports 66 focused Windows/Vulkan-validation tests passing and no VUIDs; I did not independently run that GPU suite. Hosted policy checks pass, while product/relinker jobs are skipped by path policy. I found no blocking issue in the change.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T14:44:41Z.
Review: CHANGES_REQUESTED
Rechecked exact head
e7da862d03403e694ffa6a1f8f9d1e19d1a3fb92against livemain2dbe9b99f577f5fad8ee675932a0603439e5eb2a. The earlier 66/66 focused Vulkan run was reported against7b415520b6; since thenmainchanged the AGC CMake registration andtests/ShaderMemory.cpp. The merged tree is clean, and I found no change to this PR’sShaderRegistry.cpporQueuedShaderCalls.cpplogic in that interval, but the required main-vs-change validation does not cover the current tree yet.Please sync the branch to current
main, preserve the test registrations, and rerun the same focused suite with the validation layer on currentmainand the resulting head. Update the tested base/head in the PR description. Local current-main conventions and whitespace checks pass; the merge-tree preview is clean. Hosted product/build jobs are skipped by path policy, and I did not independently run the GPU tests.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-27T10:17:48Z.
Review: CHANGES_REQUESTED
The change itself looks right:
DrainShaderWritesis applied before each callee page, call-table descriptor and table read, bounded to the bytes read, andagc_driver_queued_shader_callsfails without it (the queued producer only releases after a drain, so the old code times out and throws).One open point, the one @MarcZX10 requested on this head: the tested base (
7b415520b6) is behindmain. Please merge currentmain, rerun the focused suite with the validation layer onmainand on the result, and update the base/head in Tested. @ycbuzi's run onmain48c160c58b(RTX 4070 SUPER, GTX 1650 SUPER, AMD iGPU, control failing onmain) is good supporting evidence, but the numbers in the description should match the head you push.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T08:15:25Z.
Review: CHANGES_REQUESTED
Re-reviewed current head
d68f894df506cb7f80d48be4424dc0092fc5d599and the latest reachability clarification.The clarification resolves the earlier question: this is a defensive ordering change, and the author found no production route on
mainthat reaches compute linking with overlapping queue-0 work pending. That does not by itself make the change incorrect; the boundedInvocationFortest documents the ordering contract. I would keep the change if it is useful as that defensive guarantee.Two integration items remain before merge:
e2a51188396df488b222521ac517cae715b3652c, while livemainis4c7d275bef89d309313d16bc2bc05d37a1b50be2. The current merge preview is clean, but main has since changedShaderRegistry.cppand the AGC CMake test registrations. Please sync to current main, preserve the queued shader-call test registration/environment, and rerun the focused validation-layer suite on the exact current-main base and resulting head. The reported 65/65 and 66/66 comparison is useful evidence for the prior base, not the current integration.ShaderRegistry.cpp. Please manually confirm the interactions and record the agreed landing order/dependencies on both sides where the overlap rule requires it. #10103’s author documents a clean source-only merge with #9899, but I found no recorded agreement covering this PR and all three overlaps.Checks I ran: current-main
git merge-tree --write-treeis clean (36b1914bb6568cc2a90eb367865a706b7b225cee),git diff --checkpasses, and current-main conventions pass. I did not run the GPU tests locally; this environment has no Vulkan device. The author-reported hardware results remain attributed to the author.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T07:36:52Z.
Review: COMMENTED
Reviewed — no blocking findings
The change appears sound from the inspected code, but I could not run the reported checks, so a formal approval is not justified.
What I ran
Reviewed head
84c3b32b3a0c738b076c39fd7f1311c25356f30fusingrepo_read.py. No tests or build commands were run; the test results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
I read every changed file listed in the manifest:
ShaderRegistry.cpp,agc_driver_queued_shader_calls_tests.cmake, andQueuedShaderCalls.cpp. No changed files were excluded. Builds, automated tests, and the author-reported red/green runs were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T14:14:04Z.
Review: APPROVED
Reviewed — looks good
The queued-write drains run before callee and call-table data are read, and the new test covers overlapping writes to all three targets.
What I ran
Reviewed head
985c295fd48048764805e01cca0fe3397e9227f3. Read the prepared description, commits, diff, manifest, and all three reviewed files. Usedrepo_read.pyto search forInvocationFor; did not run tests or builds. No merged-preview check was run.Results
Negative control
Not run. The description reports red/green results for the new test; I did not independently verify them.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
The reported tests and red/green results were not independently run. Production caller reachability, hardware behavior, and excluded files were not verified;
files.jsonlists no excluded files.To get this to a good state
Nothing is required.
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.