Skip to content

fix(agc): order raw shader reads after queued code writes - #6326

Open
JJenkx wants to merge 1 commit into
boykopovar:mainfrom
JJenkx:fix/queued-raw-shader-reads
Open

JJenkx wants to merge 1 commit into
boykopovar:mainfrom
JJenkx:fix/queued-raw-shader-reads

Conversation

@JJenkx

@JJenkx JJenkx commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What

A raw shader read behind a queued write to the same code can return the old program. Queue-0 draw commits now run through DrawPipeline, but ReadRawShader only flushes work already recorded by the GPU recorder. A pending pipeline commit is not yet visible to that flush. Both a cached-code comparison and a first-time code read can therefore get ahead of the write.

Drain overlapping queued writes before comparing a cached raw snapshot and before reading each new code span. The drain runs outside the raw-shader cache mutex. Reads outside the queue-0 pipeline, and reads with no overlapping pending write, retain the existing path. No shader instruction semantics, registration policy, or cache format changes.

The CPU-only agc_driver_queued_raw_shader regression exercises cached and fresh reads through the real pipeline committer and guest-memory write path. The queued writer waits until the read returns or its bounded delay expires; the read must observe the replacement program. The cases also run separately as agc_driver_queued_raw_shader_tests cached and ... fresh. No PS5 assets or GPU are required by this regression.

This is independent of #6188 and needs no commits from it. #5751 changes registration/range bookkeeping in the same source file; this PR changes ordering of code reads and does not replace that work.

Tested

Based on main 341613ab62b979e429daa1be5ac2fe524a737df6, public head 6cd8b7240. Linux x86-64 GCC Release, renderer SPIRV-Tools enabled: full runtime libraries and all selected executables build. All 10 selected CTest cases pass without skips on both Radeon RX 6650 XT / RADV Mesa 26.2.4 and lavapipe (6.47 s / 6.58 s). Besides the new CPU regression, these cover draw-cache reuse with GPL on/off, validation and inline modes, draw-write ranges, pipelined DMA/fills and predication. Conventions and whitespace pass.

Negative controls replace only ShaderRegistry.cpp with main's version. Both selectors exit 1 with cached raw shader read ignored a queued write to its code / fresh raw shader read ignored a queued write to its code. The executable SHA-256 stays 4f87301733885662f3e6422eb053b95aab8d53372269a63dcb1c18a6f4189bbd through these controls and the restored-source build. The fix is restored and the full libraries rebuilt before the final passing tests.

The local validation tree differs from the public head only by a private SPIRV-Tools teardown-repair gitlink, excluded from this PR. These local results do not independently validate the official dependency pin. Contributor-reported official-pin and full-suite results are recorded below; Windows validation remains pending. No title unblock or FPS improvement is claimed.

Contributor-reported validation by Dextroid17: head 6cd8b7240 cleanly merged onto main 84b0d2f24, CachyOS Linux 7.2.9, GCC 16.2.1, Release, lavapipe, ANYPS5_REQUIRE_VULKAN=1, ctest -j16.

  • With SPIRV-Tools ON and the unchanged official pin 7f2d9ee92, cached and fresh selectors each pass 25/25 with this fix and fail 25/25 with only ShaderRegistry.cpp restored from main; restoring the fix and rebuilding passes another 25/25 each.
  • The ON full suite reports 1368/1369 in each of three runs, with 62 tests skipped on lavapipe. agc_compute_pipeline_replay fails with replay did not export a pipeline cache header; the contributor reproduces that failure with main's ShaderRegistry.cpp as well. These are not all-green full-suite results.
  • With SPIRV-Tools OFF, the full suite reports 1361/1361 in each of three runs. The queued raw shader regression passes 50/50 with the fix and fails 50/50 with main's ShaderRegistry.cpp. Conventions pass on the merged tree.

These results were reported by the contributor, whose testing was AI-assisted with Claude Code; they were not reproduced locally. No Windows testing was reported.

Checklist

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6234 core/libs/prx/libSceAgcDriver/CMakeLists.txt L1832
PR 6291 core/libs/prx/libSceAgcDriver/CMakeLists.txt L1832
PR 6606 core/libs/prx/libSceAgcDriver/CMakeLists.txt L1832
PR 6946 core/libs/prx/libSceAgcDriver/CMakeLists.txt L1832
PR 6947 core/libs/prx/libSceAgcDriver/CMakeLists.txt L1832

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1341 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 1368 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 1395 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 2434 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 4650 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 4891 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5021 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5115 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 5371 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5426 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5499 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5925 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6044 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6185 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6186 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6188 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 6192 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6280 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6300 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6320 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6360 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6412 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6481 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6486 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6490 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6499 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6501 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6503 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6535 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6683 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6741 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6747 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6763 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6788 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6808 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6867 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 6868 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6905 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6937 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6941 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6963 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6977 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 7201 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7223 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7332 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7642 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp

This was referenced Oct 15, 2026
This was referenced Oct 15, 2026
@github-actions github-actions Bot added build agc libSceAgc* labels Oct 15, 2026
@Dextroid17

Copy link
Copy Markdown
Contributor

I ran this on Linux with the official SPIRV-Tools pin and the full test suite, the two things your Tested section lists as not covered.

Setup: head 6cd8b7240 merged onto main 84b0d2f24 (clean merge; the branch is 1,020 commits behind), CachyOS Linux 7.2.9, GCC 16.2.1, Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON as in build.yml, with 3rdparty/SPIRV-Tools at the pinned 7f2d9ee92 and no local changes. Tests ran on lavapipe with ANYPS5_REQUIRE_VULKAN=1, ctest -j16.

SPIRV-Tools ON, official pin                          with this PR   ShaderRegistry.cpp from main
agc_driver_queued_raw_shader_tests cached (25 runs)   25/25 pass     0/25 ("cached raw shader read ignored a queued write to its code")
agc_driver_queued_raw_shader_tests fresh  (25 runs)   25/25 pass     0/25 ("fresh raw shader read ignored a queued write to its code")
after restoring the file and rebuilding               25/25 each
full ctest, 3 runs                                    1368/1369 each (the one failure is local, see below), 62 skipped on lavapipe

The one failure, agc_compute_pipeline_replay (replay did not export a pipeline cache header), also fails on my machine with ShaderRegistry.cpp from main, and it passes on CI's main build, so it is something local to my setup and not this change.

With SPIRV-Tools OFF (the CMake default), full ctest passed 1361/1361 in each of 3 runs, and agc_driver_queued_raw_shader passed 50/50 through ctest with the fix and 0/50 with ShaderRegistry.cpp from main. tools/check_conventions.py passes on the merge.

I did not test Windows.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants