fix(libSceAgc): encode ACQUIRE_MEM ranges and fields as the console does #18479

Merged
LeandroLP23 merged 2 commits from upstream-pr/18479 into main 2026-11-16 06:05:40 +00:00
LeandroLP23 commented 2026-11-11 17:43:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-11-11T17:43:59Z.


What

The follow-up to #16855 that xXPBSXx agreed to there. #16855 made the poll and cache control words match a PS5. This makes the rest of the ACQUIRE_MEM packet match two sets of console packets:

sceAgcDcbAcquireMem and sceAgcAcbAcquireMem now write the packet through one function, Agc::Command::WriteAcquireMem.

Field main Now Measured by
Engine (word 1 bit 31) ACB writes 1; DCB throws for engine > 1 ACB writes 0; DCB keeps the low bit prosper (ACB 0; DCB 0x11 → 1, 0x22 → 0)
cbDbOp kept whole; throws above 31 bits keeps bits 6-14, 25 and 26, the CB and DB fields of CP_COHER_CNTL #16855 (0x7fffffff → 0x06007fc0; 0x1-0x10, 0x10000, 0x100000 dropped; 0x100, 0x1000 kept), prosper (0x22222222 → 0x02002200, 0x44444444 → 0x04004440)
Whole range a size of 2^40 or more, or a base at or above 2^40: size 0, base 0 cbDbOp bit 14 or 26 (DB): page 1 to the top of a 48-bit space (0xfffffffe, 0xff, 1, 0) #16855 (0x7fffffff), prosper (0x44444444)
Size 32 bits; whole range from 2^40 rounded outward to 256 bytes with the high byte in word 3; a size whose block count does not fit those 40 bits covers the base up to the top #16855 (sizes 0 to 2^40 and 0xffffffffffffffff)
Base low 32 bits of the page page with 24 high bits in word 5 prosper (0x3333333344444444 → 0x33444444, 0x333333)
gcrControl throws above 19 bits keeps 19 bits, then sets bit 15 with bit 14 as #16855 does prosper (0x11111111 → 0x11111)

Nothing throws any more; the console returned the packet for every argument above.

Not measured, recorded in the libSceAgc debt:

  • Which DB bit selects the whole range. Every measured value that did had both bits 14 and 26, and every value without either didn't.
  • Where a size between 2^40 and 2^64 - 1 switches to "up to the top". Here it is the first size whose rounded block count does not fit the 40-bit field, just under 2^48.

The old debt entry for the 2^40 boundary is removed: #16855 measured 2^40 as a plain block count.

Tests: agc_commands now checks:

  • #16855's size, base and cbDbOp packets, word for word;
  • the whole range for bit 14, bit 26 and 0x7fffffff;
  • the largest size that fits the 40-bit block count, and the sizes just above it, which take the range up to the top;
  • a high base, a DCB engine of 3, gcrControl above 19 bits, and the ACB engine.

The rejection cases that no longer throw are removed. The sceAgcAcquireMemSetEngine checks use cbDbOp 0x1200, since 0x1234 loses its low bits now.

Tested

Windows 11, Radeon 860M, MinGW GCC Release, on main f57c971559.

  • agc_commands passes. Negative control: with main's three ACQUIRE_MEM sources and these tests, it fails.
  • prosper's oracle (#17730): all six ACQUIRE_MEM rows match the console. On main, four of them throw and two differ. This needs #17730's replay to pass zero for the arguments on the stack: prosper's DCB cases give five integers, so pollCycles (the seventh argument) is read from the stack. I added that to #17730.
  • ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R '^(agc|job)': 1607 of 1616 pass. The other 9 also fail on main on this machine: eight float16 shader tests and agc_driver_sample_order_grid_reference.
  • tools/check_conventions.py --base origin/main passes.
  • Overlap: tools/pr_overlap.py --branch merged all three overlapping pull requests cleanly. It could not compare #14212 and #17742, which conflict with main:
    • #14212 rewraps the 2^40 debt entry this removes;
    • #17742 edits other libSceAgc debt entries.

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: none (#16855 is merged)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon 860M (AMD proprietary driver)
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5264127823 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18479). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-11-11T17:43:59Z. --- ### What The follow-up to #16855 that xXPBSXx agreed to there. #16855 made the poll and cache control words match a PS5. This makes the rest of the ACQUIRE_MEM packet match two sets of console packets: - the ~50 packets xXPBSXx measured on #16855 (firmware 11.60); - the six ACQUIRE_MEM rows of [prosper's console oracle](https://github.com/mattias800/prosper/blob/3ea5cb9a846b6dcd00f5073360462bbda4f72288/prosper/tests/data/console_oracle/agcbuild.golden.tsv). `sceAgcDcbAcquireMem` and `sceAgcAcbAcquireMem` now write the packet through one function, `Agc::Command::WriteAcquireMem`. | Field | `main` | Now | Measured by | |---|---|---|---| | Engine (word 1 bit 31) | ACB writes 1; DCB throws for `engine` > 1 | ACB writes 0; DCB keeps the low bit | prosper (ACB 0; DCB `0x11` → 1, `0x22` → 0) | | `cbDbOp` | kept whole; throws above 31 bits | keeps bits 6-14, 25 and 26, the CB and DB fields of `CP_COHER_CNTL` | #16855 (`0x7fffffff` → `0x06007fc0`; `0x1`-`0x10`, `0x10000`, `0x100000` dropped; `0x100`, `0x1000` kept), prosper (`0x22222222` → `0x02002200`, `0x44444444` → `0x04004440`) | | Whole range | a size of 2^40 or more, or a base at or above 2^40: size 0, base 0 | `cbDbOp` bit 14 or 26 (DB): page 1 to the top of a 48-bit space (`0xfffffffe`, `0xff`, 1, 0) | #16855 (`0x7fffffff`), prosper (`0x44444444`) | | Size | 32 bits; whole range from 2^40 | rounded outward to 256 bytes with the high byte in word 3; a size whose block count does not fit those 40 bits covers the base up to the top | #16855 (sizes 0 to 2^40 and `0xffffffffffffffff`) | | Base | low 32 bits of the page | page with 24 high bits in word 5 | prosper (`0x3333333344444444` → `0x33444444`, `0x333333`) | | `gcrControl` | throws above 19 bits | keeps 19 bits, then sets bit 15 with bit 14 as #16855 does | prosper (`0x11111111` → `0x11111`) | Nothing throws any more; the console returned the packet for every argument above. **Not measured, recorded in the libSceAgc debt:** - Which DB bit selects the whole range. Every measured value that did had both bits 14 and 26, and every value without either didn't. - Where a size between 2^40 and 2^64 - 1 switches to "up to the top". Here it is the first size whose rounded block count does not fit the 40-bit field, just under 2^48. The old debt entry for the 2^40 boundary is removed: #16855 measured 2^40 as a plain block count. **Tests:** `agc_commands` now checks: - #16855's size, base and `cbDbOp` packets, word for word; - the whole range for bit 14, bit 26 and `0x7fffffff`; - the largest size that fits the 40-bit block count, and the sizes just above it, which take the range up to the top; - a high base, a DCB `engine` of 3, `gcrControl` above 19 bits, and the ACB engine. The rejection cases that no longer throw are removed. The `sceAgcAcquireMemSetEngine` checks use `cbDbOp` `0x1200`, since `0x1234` loses its low bits now. ### Tested Windows 11, Radeon 860M, MinGW GCC Release, on `main` `f57c971559`. - `agc_commands` passes. **Negative control:** with `main`'s three ACQUIRE_MEM sources and these tests, it fails. - **prosper's oracle (#17730):** all six ACQUIRE_MEM rows match the console. On `main`, four of them throw and two differ. This needs #17730's replay to pass zero for the arguments on the stack: prosper's DCB cases give five integers, so `pollCycles` (the seventh argument) is read from the stack. I added that to #17730. - `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R '^(agc|job)'`: 1607 of 1616 pass. The other 9 also fail on `main` on this machine: eight float16 shader tests and `agc_driver_sample_order_grid_reference`. - `tools/check_conventions.py --base origin/main` passes. - **Overlap:** `tools/pr_overlap.py --branch` merged all three overlapping pull requests cleanly. It could not compare #14212 and #17742, which conflict with `main`: - #14212 rewraps the 2^40 debt entry this removes; - #17742 edits other libSceAgc debt entries. ### 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: none (#16855 is merged) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon 860M (AMD proprietary driver) - [x] AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-11-12 14:27:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T14:27:29Z.

Review: COMMENTED


Reviewed — no blocking findings

The diff moves the ACQUIRE_MEM encoding for sceAgcDcbAcquireMem and sceAgcAcbAcquireMem into one function, and the code I read matches the description. One non-blocking edge case at the 2^48 cutoff is unmeasured on the console.

What I ran

  • Head: 8d21d67e961136e4422de53a0d986701b8756b5e, base main.
  • No build and no tests. I read the code only.
  • Reader calls:
python3 repo_read.py cat core/libs/prx/libSceAgc/Command/src/Memory.cpp 1 12
python3 repo_read.py cat core/libs/prx/libSceAgc/Acb/src/Memory.cpp 1 12
python3 repo_read.py cat core/libs/prx/libSceAgc/DcbFlow/src/Memory.cpp 1 12
python3 repo_read.py search AcquireMem
  • Ruling sections read: Readable reviews, Accuracy and evidence, Standard PR response format.

Results

Check Result Note
Build and agc_commands not run Author reports a pass; see Not verified
Include paths of the three call sites passed Read with the reader
Expected values in the new tests not run Hand-checked against the arithmetic; not executed
Callers of AcquireMem passed Found with the reader; see Not verified

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceAgc/Command/src/Memory.cpp:14: for a size from 2^48 − 255 to 2^48 − 1 with a 256-byte-aligned base, (sizeBytes + 0xff) >> 8 is 2^40. The high field keeps only 8 bits, so the packet encodes size 0. The < (1ull << 48u) guard does not catch this, and no test covers the range. The console's result there is unmeasured (the debt entry says the switch point is unmeasured), so this is a decision for the author: either move the cutoff below the wrap, or say which packet a size in that range should produce, and add a case to Commands.cpp.

Not verified

  • Build and tests: I ran nothing. The author reports agc_commands passing with a negative control, the prosper oracle rows matching, and ctest -R '^(agc|job)' at 1607 of 1616. Those are author-reported runs.
  • The ACB engine bit changes from 1 to 0 (Acb/src/Memory.cpp:14). Two callers in core/libs/prx/libSceJobManager/Export.cpp (lines 92 and 528) use sceAgcAcbAcquireMem, so their packets change too. Whether the console's compute path needs engine 1 is not verified here. The PR cites the measurement for engine 0 but does not state the context it was taken in.
  • Console behaviour for the whole-range bit (14 or 26) and for sizes above 2^40 is unmeasured, as the PR's own debt entry says.
  • Commands.cpp and docs/dev/debt/libSceAgc.md were read only through their diff hunks, not in full.

Sources

  • Code at head 8d21d67e96, read through the reader. No external permalinks cited.

To get this to a good state

  • Author: decide the encoding for sizes from 2^48 − 255 to 2^48 − 1, add a test for it, and rerun agc_commands on the new head.
  • Author: confirm that engine 0 is right for the job manager's ACB packets, with the measurement context in the PR.

Files read: the six files in files.json under reviewed, through their diff hunks and the head headers above. Excluded by rule: none.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5876120169 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18479#pullrequestreview-5876120169). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-12T14:27:29Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The diff moves the ACQUIRE_MEM encoding for `sceAgcDcbAcquireMem` and `sceAgcAcbAcquireMem` into one function, and the code I read matches the description. One non-blocking edge case at the 2^48 cutoff is unmeasured on the console. ## What I ran - Head: `8d21d67e961136e4422de53a0d986701b8756b5e`, base `main`. - No build and no tests. I read the code only. - Reader calls: ``` python3 repo_read.py cat core/libs/prx/libSceAgc/Command/src/Memory.cpp 1 12 python3 repo_read.py cat core/libs/prx/libSceAgc/Acb/src/Memory.cpp 1 12 python3 repo_read.py cat core/libs/prx/libSceAgc/DcbFlow/src/Memory.cpp 1 12 python3 repo_read.py search AcquireMem ``` - Ruling sections read: Readable reviews, Accuracy and evidence, Standard PR response format. ## Results | Check | Result | Note | |---|---|---| | Build and `agc_commands` | not run | Author reports a pass; see Not verified | | Include paths of the three call sites | passed | Read with the reader | | Expected values in the new tests | not run | Hand-checked against the arithmetic; not executed | | Callers of `AcquireMem` | passed | Found with the reader; see Not verified | ## Findings ### Blocking None. ### Non-blocking - `core/libs/prx/libSceAgc/Command/src/Memory.cpp:14`: for a size from 2^48 − 255 to 2^48 − 1 with a 256-byte-aligned base, `(sizeBytes + 0xff) >> 8` is 2^40. The high field keeps only 8 bits, so the packet encodes size 0. The `< (1ull << 48u)` guard does not catch this, and no test covers the range. The console's result there is unmeasured (the debt entry says the switch point is unmeasured), so this is a decision for the author: either move the cutoff below the wrap, or say which packet a size in that range should produce, and add a case to `Commands.cpp`. ## Not verified - Build and tests: I ran nothing. The author reports `agc_commands` passing with a negative control, the prosper oracle rows matching, and `ctest -R '^(agc|job)'` at 1607 of 1616. Those are author-reported runs. - The ACB engine bit changes from 1 to 0 (`Acb/src/Memory.cpp:14`). Two callers in `core/libs/prx/libSceJobManager/Export.cpp` (lines 92 and 528) use `sceAgcAcbAcquireMem`, so their packets change too. Whether the console's compute path needs engine 1 is not verified here. The PR cites the measurement for engine 0 but does not state the context it was taken in. - Console behaviour for the whole-range bit (14 or 26) and for sizes above 2^40 is unmeasured, as the PR's own debt entry says. - `Commands.cpp` and `docs/dev/debt/libSceAgc.md` were read only through their diff hunks, not in full. ## Sources - Code at head `8d21d67e96`, read through the reader. No external permalinks cited. ## To get this to a good state - Author: decide the encoding for sizes from 2^48 − 255 to 2^48 − 1, add a test for it, and rerun `agc_commands` on the new head. - Author: confirm that engine 0 is right for the job manager's ACB packets, with the measurement context in the PR. Files read: the six files in `files.json` under `reviewed`, through their diff hunks and the head headers above. Excluded by rule: none.
MarcZX10 commented 2026-11-14 00:25:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T00:25:40Z.

Review: COMMENTED


Reviewed — comments

Nothing blocks this review, but the range encoding needs clarification before its behavior can be confidently assessed.

What I ran

  • Reviewed head a4f24bc2653b41a3ba96e59b5c44f049ace4c33e using repo_read.py.
  • No tests or build commands were run.

Results

Check Result Note
Source review passed All six changed files read
Tests not run Author-reported results only

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceAgc/Command/src/Memory.cpp:14: The new size calculation switches to “range to the top” when the rounded block count would exceed the 40-bit field. The description identifies this switch point as not measured on console, while the tests assert behavior immediately around the inferred boundary. Please record that this is an inference and add console evidence when available; the current tests establish the implementation’s arithmetic, not its hardware behavior.

Not verified

  • Tests, build, console behavior, and author-reported CI results were not independently verified.
  • All changed files listed in the manifest were read. No files were excluded by the review bundle.

To get this to a good state

Nothing is required. The range-boundary comment above is optional.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5899973604 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18479#pullrequestreview-5899973604). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T00:25:40Z. **Review:** COMMENTED --- # Reviewed — comments Nothing blocks this review, but the range encoding needs clarification before its behavior can be confidently assessed. ## What I ran - Reviewed head `a4f24bc2653b41a3ba96e59b5c44f049ace4c33e` using `repo_read.py`. - No tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | All six changed files read | | Tests | not run | Author-reported results only | ## Findings ### Blocking None. ### Non-blocking - `core/libs/prx/libSceAgc/Command/src/Memory.cpp:14`: The new size calculation switches to “range to the top” when the rounded block count would exceed the 40-bit field. The description identifies this switch point as not measured on console, while the tests assert behavior immediately around the inferred boundary. Please record that this is an inference and add console evidence when available; the current tests establish the implementation’s arithmetic, not its hardware behavior. ## Not verified - Tests, build, console behavior, and author-reported CI results were not independently verified. - All changed files listed in the manifest were read. No files were excluded by the review bundle. ## To get this to a good state Nothing is required. The range-boundary comment above is optional.
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!18479
No description provided.