fix(agc): accept four GCN packet forms in a PS4 title's command buffers #20127

Merged
adam25136 merged 1 commit from upstream-pr/20127 into main 2026-11-16 08:09:37 +00:00
adam25136 commented 2026-11-14 17:10:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adam25136 on 2026-11-14T17:10:20Z.


What

In a PS4 title (ShaderRecompiler::GcnGuestShaders(), the gate that DATA_SEL 4 in RELEASE_MEM already uses), AGC's packet check (Pm4::Validate) accepts four GCN packet forms:

  • a typed user-data marker NOP (payload 0x6875xxxx), whose payload GNM already sets to 0 at the top level. A flip reservation still throws: a 64-dword marker NOP (the size of GNM's reservation), or the markers 0x68750777 and 0x68750778;
  • header bit 1 (compute shader type) on a compute-queue packet other than a NOP;
  • the seven-dword GCN RELEASE_MEM. Execute, ReleaseMemValue and DecodeLabelWrite read dwords 0 to 6, and EopRelease takes only eight-dword releases. Two cases throw in the check: an interrupt (INT_SEL other than 0 or 3, the values releaseInterrupt treats as none), since the GCN form has no interrupt context dword; and dword 1 bits beyond the event type and index (0xf3f, what GNM keeps when it lowers EVENT_WRITE_EOP), so no GCN cache bit is read with the PS5 layout;
  • bit 16 of the seven-dword ACQUIRE_MEM control word, gfx7's TC_VOL_ACTION_ENA (gfx_7_2_sh_mask.h, CP_COHER_CNTL__TC_VOL_ACTION_ENA_MASK 0x10000). AGC reads that word only in this check (and in UsesGpuCacheBarrier, which only tests call), so the bit changes nothing it does.

GNM rewrites only the top-level packets of a PS4 submission (Lower() in libSceGnmDriver/Export.cpp). AGC copies the buffers that an INDIRECT_BUFFER calls when the submission arrives (copySegment in Driver/Queues/Submission.cpp), and its check is the one that meets them. PS5 titles are unchanged. DealPotato reported these forms in Second Son (CUSA00004) on 2026-10-18, with a local workaround in GNM.

inFAMOUS Second Son (CUSA00223) meets all four in a 324-dword buffer that its compute queue ring calls: DWORD 263 (c0041000 68754000 00000000 00000000 00000000 00000000), DWORD 269 (c0054902 0000062f 23000000 4be84430 00000002 00000001 00000000, header bit 1) and DWORD 303 (c0055800 00c58000 00000000 00000000 00000000 00000000 0000000a). Without this change, local runs on 2026-11-11, each with local compute-queue code and the earlier forms accepted by local edits, stopped at each of the three in turn. With main c7102526b5, #18546 and this commit (f7885117b6, the same changed lines as the head) merged locally, plus four uncommitted local changes for earlier stops (in the relinker, libSceSysmodule, libSceDiscMap and libSceVideoOut; none in AGC or GNM), 3 of 3 starts log no rejected submission. Their failure reports list that buffer and a second compute submission of 68 dwords with the same forms, and each start stops later, in the shader recompiler: GCN MTBUF opcode 3 at program counter 8 is not implemented.

testGcnCalledBufferPacketForms in tests/Pm4.cpp checks that each form is refused without a PS4 title and accepted with one, and that the cases above still throw. It also submits a called buffer with packets in the three inFAMOUS forms on queue 0x20 and checks the release's write. The debt entry "PS4 command buffers that an INDIRECT_BUFFER calls" lists what still throws in such buffers.

Overlap: tools/pr_overlap.py --branch (in a full clone, this head merged onto main 87d51b0307): 141 of 1,529 open pull requests share a file with this branch. Of the 80 it could compare, only #18956 (mjnhbg3) shares lines: it adds checks under the RELEASE_MEM size line that this change replaces, so whichever merges second needs a rebase there. It could not compare 61 that conflict with main. In GitHub's patches of these, 54 share only the debt file, with no edit next to this entry. Of the 7 that change Pm4.cpp or its test, only #18914 (atinseau) changes the same checks. From reading its patch (not run): its new fast path refuses the marker NOP before the general check, so with both merged the PS4 gate has to go there too, or this test's first accept in a PS4 title fails. None of the open pull requests that share a file, nor #6977 (a draft) or #18546, accepts these forms.

Tested

Windows 10 Pro 22H2 (19045), i9-12900KF, NVIDIA GeForce RTX 5080 (10de:2c02, driver 621.14), WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, ANYPS5_ENABLE_SPIRV_TOOLS=OFF unless stated. Head 2ff14e29d3 on main f1822f7a84, rebased from 2ab6987cc4 on bacd553166 with the same changed lines; on it, agc_driver_pm4 passes 3 of 3 runs and all 29 agc_driver_pm4* tests pass. The results below are from 2ab6987cc4, except the selected tests, the validation runs and the layer check, which ran on fae9636a97 (it differs only in one error message, the test's copy of it and the debt entry's wording) merged onto main 3e63c9f68f.

  • agc_driver_pm4 passes in 3 of 3 runs, and all 29 agc_driver_pm4* tests pass. The 29 also pass in one run in a build with ANYPS5_ENABLE_SPIRV_TOOLS=ON (as the Linux CI job builds).
  • With Pm4.cpp from main (the test kept), agc_driver_pm4 fails with typed user-data and legacy flip markers are not implemented. With each part of the change reverted on its own (restored afterwards):
Reverted Fails with
the marker NOP rule typed user-data and legacy flip markers are not implemented
the flip marker guard expected PM4 rejection (a flip marker is accepted)
the flip reservation guard expected PM4 rejection (a 64-dword marker NOP is accepted)
header bit 1 on compute queues PM4 header flags 0x2 are not implemented
the seven-dword RELEASE_MEM invalid packet size
its dword 1 limit expected PM4 rejection (bit 17 of dword 1 is accepted)
its interrupt refusal expected PM4 rejection (INT_SEL 1 is accepted)
ACQUIRE_MEM bit 16 unsupported ACQUIRE_MEM control flags
  • Selected tests: tools/select_tests.py picks 2,876 tests for the changed files. With fae9636a97 merged onto main (select_tests.py ctest build --parallel 4 --timeout 120, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1), 2,857 pass and 19 do not run, the same 19 that do not run in main's full suite on this machine (5,562 tests). One of them, agc_driver_upload_cache_read_only_flush, has a test program that does not build on Windows (setenv, open #19899); both sides were built with ninja's -k 0, and it was the only target that failed. main's full suite also failed agc_driver_dumped_constant_capture once; it then passed 5 of 5 runs on that main and 5 of 5 with fae9636a97 merged.
  • Validation: the tests matching ^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu, 1,732 of the selection and 1,824 in main's run, through ctest -V --parallel 4 with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (1.4.367) and VK_LOADER_LAYERS_DISABLE=~implicit~: all pass, and both logs have the same 61 messages in the same 14 tests, with no new VUID- ID and no "was not found but was requested by env var VK_INSTANCE_LAYERS" line. With VK_LOADER_DEBUG=layer added, on that main and with fae9636a97 merged: agc_driver_alpha_to_coverage shows the loader inserting the layer on both sides, and the 29 agc_driver_pm4* tests pass on both sides with no loader line, since they do not open Vulkan.
  • python tools/check_conventions.py --base origin/main with this title and description: "All conventions checks passed."

Not covered: AMD and Intel GPUs, Linux, a PS5 or PS4.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #18956
  • Fixes: none
  • Unblocks: CUSA00223 #8214, with #18546
  • GPUs tested: NVIDIA GeForce RTX 5080 (10de:2c02), driver 621.14, Windows 10 Pro 22H2
  • AI-assisted: yes. Claude Code found the forms in inFAMOUS's logs, wrote the change, the test and the debt entry, ran the builds, tests and game runs, and drafted this description; separate review agents checked it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5314035137 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20127). Originally posted by [adam25136](https://github.com/adam25136) on 2026-11-14T17:10:20Z. --- ### What In a PS4 title (`ShaderRecompiler::GcnGuestShaders()`, the gate that `DATA_SEL 4` in `RELEASE_MEM` already uses), AGC's packet check (`Pm4::Validate`) accepts four GCN packet forms: - a typed user-data marker NOP (payload `0x6875xxxx`), whose payload GNM already sets to 0 at the top level. A flip reservation still throws: a 64-dword marker NOP (the size of GNM's reservation), or the markers `0x68750777` and `0x68750778`; - header bit 1 (compute shader type) on a compute-queue packet other than a NOP; - the seven-dword GCN `RELEASE_MEM`. `Execute`, `ReleaseMemValue` and `DecodeLabelWrite` read dwords 0 to 6, and `EopRelease` takes only eight-dword releases. Two cases throw in the check: an interrupt (`INT_SEL` other than 0 or 3, the values `releaseInterrupt` treats as none), since the GCN form has no interrupt context dword; and dword 1 bits beyond the event type and index (`0xf3f`, what GNM keeps when it lowers `EVENT_WRITE_EOP`), so no GCN cache bit is read with the PS5 layout; - bit 16 of the seven-dword `ACQUIRE_MEM` control word, gfx7's `TC_VOL_ACTION_ENA` ([`gfx_7_2_sh_mask.h`](https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/include/asic_reg/gca/gfx_7_2_sh_mask.h), `CP_COHER_CNTL__TC_VOL_ACTION_ENA_MASK 0x10000`). AGC reads that word only in this check (and in `UsesGpuCacheBarrier`, which only tests call), so the bit changes nothing it does. GNM rewrites only the top-level packets of a PS4 submission (`Lower()` in `libSceGnmDriver/Export.cpp`). AGC copies the buffers that an `INDIRECT_BUFFER` calls when the submission arrives (`copySegment` in `Driver/Queues/Submission.cpp`), and its check is the one that meets them. PS5 titles are unchanged. DealPotato [reported these forms](https://github.com/boykopovar/AnyPS5/pull/6977#issuecomment-6253259006) in Second Son (CUSA00004) on 2026-10-18, with a local workaround in GNM. inFAMOUS Second Son (CUSA00223) meets all four in a 324-dword buffer that its compute queue ring calls: DWORD 263 (`c0041000 68754000 00000000 00000000 00000000 00000000`), DWORD 269 (`c0054902 0000062f 23000000 4be84430 00000002 00000001 00000000`, header bit 1) and DWORD 303 (`c0055800 00c58000 00000000 00000000 00000000 00000000 0000000a`). Without this change, local runs on 2026-11-11, each with local compute-queue code and the earlier forms accepted by local edits, stopped at each of the three in turn. With `main` `c7102526b5`, #18546 and this commit (`f7885117b6`, the same changed lines as the head) merged locally, plus four uncommitted local changes for earlier stops (in the relinker, libSceSysmodule, libSceDiscMap and libSceVideoOut; none in AGC or GNM), 3 of 3 starts log no rejected submission. Their failure reports list that buffer and a second compute submission of 68 dwords with the same forms, and each start stops later, in the shader recompiler: `GCN MTBUF opcode 3 at program counter 8 is not implemented`. `testGcnCalledBufferPacketForms` in `tests/Pm4.cpp` checks that each form is refused without a PS4 title and accepted with one, and that the cases above still throw. It also submits a called buffer with packets in the three inFAMOUS forms on queue 0x20 and checks the release's write. The debt entry "PS4 command buffers that an INDIRECT_BUFFER calls" lists what still throws in such buffers. Overlap: `tools/pr_overlap.py --branch` (in a full clone, this head merged onto `main` `87d51b0307`): 141 of 1,529 open pull requests share a file with this branch. Of the 80 it could compare, only #18956 (mjnhbg3) shares lines: it adds checks under the `RELEASE_MEM` size line that this change replaces, so whichever merges second needs a rebase there. It could not compare 61 that conflict with `main`. In GitHub's patches of these, 54 share only the debt file, with no edit next to this entry. Of the 7 that change `Pm4.cpp` or its test, only #18914 (atinseau) changes the same checks. From reading its patch (not run): its new fast path refuses the marker NOP before the general check, so with both merged the PS4 gate has to go there too, or this test's first accept in a PS4 title fails. None of the open pull requests that share a file, nor #6977 (a draft) or #18546, accepts these forms. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 10 Pro 22H2 (19045), i9-12900KF, NVIDIA GeForce RTX 5080 (`10de:2c02`, driver 621.14), WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, `ANYPS5_ENABLE_SPIRV_TOOLS=OFF` unless stated. Head `2ff14e29d3` on `main` `f1822f7a84`, rebased from `2ab6987cc4` on `bacd553166` with the same changed lines; on it, `agc_driver_pm4` passes 3 of 3 runs and all 29 `agc_driver_pm4*` tests pass. The results below are from `2ab6987cc4`, except the selected tests, the validation runs and the layer check, which ran on `fae9636a97` (it differs only in one error message, the test's copy of it and the debt entry's wording) merged onto `main` `3e63c9f68f`. - `agc_driver_pm4` passes in 3 of 3 runs, and all 29 `agc_driver_pm4*` tests pass. The 29 also pass in one run in a build with `ANYPS5_ENABLE_SPIRV_TOOLS=ON` (as the Linux CI job builds). - With `Pm4.cpp` from `main` (the test kept), `agc_driver_pm4` fails with `typed user-data and legacy flip markers are not implemented`. With each part of the change reverted on its own (restored afterwards): | Reverted | Fails with | |---|---| | the marker NOP rule | `typed user-data and legacy flip markers are not implemented` | | the flip marker guard | `expected PM4 rejection` (a flip marker is accepted) | | the flip reservation guard | `expected PM4 rejection` (a 64-dword marker NOP is accepted) | | header bit 1 on compute queues | `PM4 header flags 0x2 are not implemented` | | the seven-dword `RELEASE_MEM` | `invalid packet size` | | its dword 1 limit | `expected PM4 rejection` (bit 17 of dword 1 is accepted) | | its interrupt refusal | `expected PM4 rejection` (`INT_SEL` 1 is accepted) | | `ACQUIRE_MEM` bit 16 | `unsupported ACQUIRE_MEM control flags` | - Selected tests: `tools/select_tests.py` picks 2,876 tests for the changed files. With `fae9636a97` merged onto `main` (`select_tests.py ctest build --parallel 4 --timeout 120`, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`), 2,857 pass and 19 do not run, the same 19 that do not run in `main`'s full suite on this machine (5,562 tests). One of them, `agc_driver_upload_cache_read_only_flush`, has a test program that does not build on Windows (`setenv`, open #19899); both sides were built with ninja's `-k 0`, and it was the only target that failed. `main`'s full suite also failed `agc_driver_dumped_constant_capture` once; it then passed 5 of 5 runs on that `main` and 5 of 5 with `fae9636a97` merged. - Validation: the tests matching `^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu`, 1,732 of the selection and 1,824 in `main`'s run, through `ctest -V --parallel 4` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (1.4.367) and `VK_LOADER_LAYERS_DISABLE=~implicit~`: all pass, and both logs have the same 61 messages in the same 14 tests, with no new `VUID-` ID and no "was not found but was requested by env var VK_INSTANCE_LAYERS" line. With `VK_LOADER_DEBUG=layer` added, on that `main` and with `fae9636a97` merged: `agc_driver_alpha_to_coverage` shows the loader inserting the layer on both sides, and the 29 `agc_driver_pm4*` tests pass on both sides with no loader line, since they do not open Vulkan. - `python tools/check_conventions.py --base origin/main` with this title and description: "All conventions checks passed." Not covered: AMD and Intel GPUs, Linux, a PS5 or PS4. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #18956 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: CUSA00223 #8214, with #18546 <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: NVIDIA GeForce RTX 5080 (`10de:2c02`), driver 621.14, Windows 10 Pro 22H2 <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes. Claude Code found the forms in inFAMOUS's logs, wrote the change, the test and the debt entry, ran the builds, tests and game runs, and drafted this description; separate review agents checked it. <!-- yes / no --> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-14 17:31:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T17:31:38Z.

Review: COMMENTED


Reviewed — no blocking findings

The changed code and all three changed files were read at head 2ff14e29d3731ee1c69e7cdf578e4cfd6b75cad5; no checks were run during this review, so I cannot recommend a formal approval.

What I ran

No commands or tests were run. I read description.md, commits.md, manifest.json, diff.patch, and the changed lines in all three changed files through repo_read.py. The author reports tests and validation in the PR description; those results were not rerun here.

Results

Check Result Note
Changed code review passed All three changed files and added lines read
Tests and validation not run Author-reported results only
Negative control not run No test mutation performed

Negative control

Could not run a negative control because no tests were run during this review.

Findings

Blocking

None identified in the code read.

Non-blocking

None.

Sources

Not verified

I did not rerun the reported test suite, validation runs, conventions check, or title launches. The report describes author-run tests, including GPU and operating-system limits; these were not independently verified. The changed files were core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp, core/libs/prx/libSceAgcDriver/tests/Pm4.cpp, and docs/dev/debt/libSceAgcDriver.md; no changed files were excluded from the prepared review artifacts.

To get this to a good state

Nothing is required. The PR description reports extensive test and validation results, but they were not rerun in this review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5906097514 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20127#pullrequestreview-5906097514). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T17:31:38Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The changed code and all three changed files were read at head `2ff14e29d3731ee1c69e7cdf578e4cfd6b75cad5`; no checks were run during this review, so I cannot recommend a formal approval. ## What I ran No commands or tests were run. I read `description.md`, `commits.md`, `manifest.json`, `diff.patch`, and the changed lines in all three changed files through `repo_read.py`. The author reports tests and validation in the PR description; those results were not rerun here. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All three changed files and added lines read | | Tests and validation | not run | Author-reported results only | | Negative control | not run | No test mutation performed | ## Negative control Could not run a negative control because no tests were run during this review. ## Findings ### Blocking None identified in the code read. ### Non-blocking None. ## Sources - [Pm4.cpp at reviewed head](https://github.com/boykopovar/AnyPS5/blob/2ff14e29d3731ee1c69e7cdf578e4cfd6b75cad5/core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp) - [PM4 tests at reviewed head](https://github.com/boykopovar/AnyPS5/blob/2ff14e29d3731ee1c69e7cdf578e4cfd6b75cad5/core/libs/prx/libSceAgcDriver/tests/Pm4.cpp) - [AGC driver debt notes at reviewed head](https://github.com/boykopovar/AnyPS5/blob/2ff14e29d3731ee1c69e7cdf578e4cfd6b75cad5/docs/dev/debt/libSceAgcDriver.md) ## Not verified I did not rerun the reported test suite, validation runs, conventions check, or title launches. The report describes author-run tests, including GPU and operating-system limits; these were not independently verified. The changed files were `core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp`, `core/libs/prx/libSceAgcDriver/tests/Pm4.cpp`, and `docs/dev/debt/libSceAgcDriver.md`; no changed files were excluded from the prepared review artifacts. ## To get this to a good state Nothing is required. The PR description reports extensive test and validation results, but they were not rerun in this review.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!20127
No description provided.