feat(agc): poll and write registers in PM4 COND_WRITE #16184

Merged
AlexWhitehouse merged 3 commits from upstream-pr/16184 into main 2026-11-15 19:50:49 +00:00
AlexWhitehouse commented 2026-11-05 20:20:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-05T20:20:16Z.


What

PM4 COND_WRITE (opcode 0x45) worked only with a memory poll and a memory destination. A register poll threw register-space COND_WRITE poll is not implemented, and a register destination threw register or scratch COND_WRITE destination is not implemented. This PR runs both for the registers the queue already models.

Packet, from AMD's Southern Islands programming guide §2.7.2 (pp. 33–34) and PAL's GFX10 packet definition (lines 521–630, nine dwords):

  • POLL_SPACE (bit 4) selects register or memory, and WRITE_SPACE (bits 8–9) selects register, memory or scratch.
  • The value read is masked and compared with the reference using function 0–6; when the comparison holds, the write data goes to the destination.
  • Register addresses are absolute dword register numbers. The bank bases are the ones PAL's SET_*_REG builders subtract (gfx9CmdUtil.cpp lines 3650, 4025 and 4084) and Mesa's sid.h defines. Mesa's ac_cmdbuf.h converts byte offsets to the same dword numbers.

Change (core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp):

  • Register poll: reads the queue's shader (0x2c00–0x2fff), context (0xa000–0xa3ff) or user-config (0xc000–0xffff) register value, using the comparison code memory polls already use.
  • Register destination: goes through the same register write as the matching SET_SH_REG, SET_CONTEXT_REG or SET_UCONFIG_REG, so a register's side effects apply. The test checks this with VGT_INDEX_TYPE (0xc243). It reports no guest memory store to capture or replay.
  • Unchanged: the memory-poll, memory-destination path. #12568 and #15136 edit that statement for frame-capture accounting, and both still merge cleanly.
  • Still throws: a poll of a register with no value written yet, addresses outside the three banks (hardware status registers included), a nonzero register-address high dword, the scratch destination, reserved control bits and memory swap modes.
  • Debt: a new docs/dev/debt/libSceAgcDriver.md entry records what still throws and that PS5 behaviour, GFX10 high-dword handling and write confirmation are not measured.

Tested

  • agc_driver_pm4 (core/libs/prx/libSceAgcDriver/tests/Pm4.cpp) gains testConditionalWriteRegisters. Every existing assertion is kept, including the existing rejections, whose register addresses are host pointers outside the modeled banks.
    • Comparisons and masks: for each bank, all seven compare functions are checked on both sides of the reference with the mask applied, and a false comparison leaves the target unchanged.
    • Register destinations: register-to-register writes are read back from the bank, and a memory poll with a register destination is checked too.
    • Isolation and side effects: a second queue's registers are unchanged, register destinations report no memory store, and a user-config destination applies its side effect.
    • Ordering: three SET_*_REG packets followed by three register-poll COND_WRITEs in one submission see the newly set values.
    • Still throwing: addresses just outside each bank, an unwritten register, the scratch destination and nonzero high dwords.
  • Linux (Ubuntu 26.04, GCC 15, lavapipe Mesa 26.0.8), with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. The run covered the 18 PM4, replay, recorder and register-key tests (agc_driver_pm4*, agc_driver_pm4_replay*, agc_driver_recorder, agc_driver_register_key):
    • main passes 18/18. With only the new test added, agc_driver_pm4 fails with register-space COND_WRITE poll is not implemented;
    • this PR passes 18/18;
    • no VUID- lines and no missing-layer messages.
  • Mutation check: reading the wrong register bank fails with COND_WRITE did not read back its register destination.
  • Windows 11, NVIDIA RTX 3060 (driver 610.88, WinLibs MinGW-w64 GCC 15.2.0, Release), with the same three variables:
    • the matching 18 tests pass at e3c04eb545, with no skips. Windows registers agc_driver_pm4_ring_report_heap where Linux registers agc_driver_pm4_priority_refused;
    • with main's Pm4.cpp, agc_driver_pm4 fails with the same message;
    • no VUID- lines and no missing-layer messages. The PM4 test creates no Vulkan instance; a VK_LOADER_DEBUG=layer rerun of agc_driver_recorder confirmed that the validation layer was inserted at instance and device level.
  • python3 tools/check_conventions.py --base origin/main: all conventions checks passed.
  • python3 tools/pr_overlap.py --branch feat/agc-cond-write-registers: no confirmed overlap.
    • It could not compare 48 PRs, all of which already conflict with main. Trial merges of all 48 add no conflicted file, and the conflict contents stay the same except for #14212 (blank lines between debt entries), which also conflicts with the new entry.
    • Of the open PRs that touch Pm4.cpp, #12568, #15136, #16054, #15610, #14330, #14130, #14110, #12944, #12567, #9893 and #6549 merge cleanly. #12315, #10249 and #6188 keep only the conflicts they already have with main.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3060, driver 610.88, Windows 11 (build 26300); Mesa lavapipe 26.0.8 (LLVM 21.1.8), Ubuntu 26.04
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5178117273 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16184). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-05T20:20:16Z. --- ### What PM4 `COND_WRITE` (opcode 0x45) worked only with a memory poll and a memory destination. A register poll threw `register-space COND_WRITE poll is not implemented`, and a register destination threw `register or scratch COND_WRITE destination is not implemented`. This PR runs both for the registers the queue already models. **Packet**, from AMD's [Southern Islands programming guide](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/programmer-references/si_programming_guide_v2.pdf) §2.7.2 (pp. 33–34) and PAL's [GFX10 packet definition](https://github.com/GPUOpen-Drivers/pal/blob/c5e800072a32f68b6ccc4422936d96167c6e0728/src/core/hw/gfxip/gfx9/chip/gfx9_plus_merged_f32_me_pm4_packets.h#L521-L630) (lines 521–630, nine dwords): - `POLL_SPACE` (bit 4) selects register or memory, and `WRITE_SPACE` (bits 8–9) selects register, memory or scratch. - The value read is masked and compared with the reference using function 0–6; when the comparison holds, the write data goes to the destination. - Register addresses are absolute dword register numbers. The bank bases are the ones PAL's `SET_*_REG` builders subtract ([`gfx9CmdUtil.cpp`](https://github.com/GPUOpen-Drivers/pal/blob/c5e800072a32f68b6ccc4422936d96167c6e0728/src/core/hw/gfxip/gfx9/gfx9CmdUtil.cpp#L3650) lines 3650, 4025 and 4084) and Mesa's [`sid.h`](https://github.com/chaotic-cx/mesa-mirror/blob/76419839238922803b96db1ddf59e1daf2c732c9/src/amd/common/sid.h#L18-L23) defines. Mesa's [`ac_cmdbuf.h`](https://github.com/chaotic-cx/mesa-mirror/blob/76419839238922803b96db1ddf59e1daf2c732c9/src/amd/common/ac_cmdbuf.h#L322-L327) converts byte offsets to the same dword numbers. **Change** (`core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp`): - **Register poll:** reads the queue's shader (`0x2c00`–`0x2fff`), context (`0xa000`–`0xa3ff`) or user-config (`0xc000`–`0xffff`) register value, using the comparison code memory polls already use. - **Register destination:** goes through the same register write as the matching `SET_SH_REG`, `SET_CONTEXT_REG` or `SET_UCONFIG_REG`, so a register's side effects apply. The test checks this with `VGT_INDEX_TYPE` (`0xc243`). It reports no guest memory store to capture or replay. - **Unchanged:** the memory-poll, memory-destination path. #12568 and #15136 edit that statement for frame-capture accounting, and both still merge cleanly. - **Still throws:** a poll of a register with no value written yet, addresses outside the three banks (hardware status registers included), a nonzero register-address high dword, the scratch destination, reserved control bits and memory swap modes. - **Debt:** a new `docs/dev/debt/libSceAgcDriver.md` entry records what still throws and that PS5 behaviour, GFX10 high-dword handling and write confirmation are not measured. ### Tested - **`agc_driver_pm4`** (`core/libs/prx/libSceAgcDriver/tests/Pm4.cpp`) gains `testConditionalWriteRegisters`. Every existing assertion is kept, including the existing rejections, whose register addresses are host pointers outside the modeled banks. - **Comparisons and masks:** for each bank, all seven compare functions are checked on both sides of the reference with the mask applied, and a false comparison leaves the target unchanged. - **Register destinations:** register-to-register writes are read back from the bank, and a memory poll with a register destination is checked too. - **Isolation and side effects:** a second queue's registers are unchanged, register destinations report no memory store, and a user-config destination applies its side effect. - **Ordering:** three `SET_*_REG` packets followed by three register-poll `COND_WRITE`s in one submission see the newly set values. - **Still throwing:** addresses just outside each bank, an unwritten register, the scratch destination and nonzero high dwords. - **Linux** (Ubuntu 26.04, GCC 15, lavapipe Mesa 26.0.8), with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`. The run covered the 18 PM4, replay, recorder and register-key tests (`agc_driver_pm4*`, `agc_driver_pm4_replay*`, `agc_driver_recorder`, `agc_driver_register_key`): - `main` passes 18/18. With only the new test added, `agc_driver_pm4` fails with `register-space COND_WRITE poll is not implemented`; - this PR passes 18/18; - no `VUID-` lines and no missing-layer messages. - **Mutation check:** reading the wrong register bank fails with `COND_WRITE did not read back its register destination`. - **Windows 11, NVIDIA RTX 3060** (driver 610.88, WinLibs MinGW-w64 GCC 15.2.0, Release), with the same three variables: - the matching 18 tests pass at e3c04eb545, with no skips. Windows registers `agc_driver_pm4_ring_report_heap` where Linux registers `agc_driver_pm4_priority_refused`; - with `main`'s `Pm4.cpp`, `agc_driver_pm4` fails with the same message; - no `VUID-` lines and no missing-layer messages. The PM4 test creates no Vulkan instance; a `VK_LOADER_DEBUG=layer` rerun of `agc_driver_recorder` confirmed that the validation layer was inserted at instance and device level. - `python3 tools/check_conventions.py --base origin/main`: all conventions checks passed. - **`python3 tools/pr_overlap.py --branch feat/agc-cond-write-registers`:** no confirmed overlap. - It could not compare 48 PRs, all of which already conflict with `main`. Trial merges of all 48 add no conflicted file, and the conflict contents stay the same except for #14212 (blank lines between debt entries), which also conflicts with the new entry. - Of the open PRs that touch `Pm4.cpp`, #12568, #15136, #16054, #15610, #14330, #14130, #14110, #12944, #12567, #9893 and #6549 merge cleanly. #12315, #10249 and #6188 keep only the conflicts they already have with `main`. ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 3060, driver 610.88, Windows 11 (build 26300); Mesa lavapipe 26.0.8 (LLVM 21.1.8), Ubuntu 26.04 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!16184
No description provided.