feat(agc): implement PM4 CONTEXT_REG_RMW #16878

Merged
AlexWhitehouse merged 2 commits from upstream-pr/16878 into main 2026-11-14 04:38:36 +00:00
AlexWhitehouse commented 2026-11-07 19:42:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-07T19:42:32Z.


What

The PM4 packet CONTEXT_REG_RMW (type-3 opcode 0x51) wasn't in the AGC driver's reference catalogue, so a command buffer containing it failed validation with opcode is not known in the reference. This PR implements it from PAL at c5e80007, the revision my #16184 (COND_WRITE) and #16345 (DMA_DATA) cite:

The packet has four dwords: the header, the context-register offset (16 bits, upper 16 reserved), a mask and data. Its effect is new = (old & ~mask) | (data & mask). PAL emits it for colour and depth state in gfx9UniversalCmdBuffer.cpp.

  • Validation: the packet is accepted only on graphics queues, as SET_CONTEXT_REG is. It must be exactly four dwords, and set reserved offset bits are rejected.
  • Execution:
    • it reads the old value from the modelled context-register state;
    • it writes the result through the same path SET_CONTEXT_REG uses, so later reads, COPY_DATA from the register and the register fingerprint all see it;
    • a register with no known value (never written, and no reset value in the model) throws instead of assuming zero.
  • Catalogue: the reference opcode catalogue grows from 56 to 57.
  • Debt: a CONTEXT_REG_RMW entry in docs/dev/debt/libSceAgcDriver.md records the throw for a register with no known value. Of the registers PAL modifies with this packet, CB_COLORn_DCC_CONTROL, DB_COUNT_CONTROL and DB_RESERVED_REG_2 have no reset value in the model. Console behaviour is unmeasured, as for the other PM4 packets.

Tested

  • New test: agc_driver_pm4_context_reg_rmw (also run inside agc_driver_pm4) covers:

    • preserved and replaced bits, and data bits outside the mask being ignored;
    • zero and full masks;
    • a fingerprint change, and a COPY_DATA readback of the register;
    • an RMW on a reset-state register;
    • packets that are too short or too long;
    • an unknown old value throwing;
    • compute-queue rejection;
    • reserved offset bits.
  • Linux x86-64 (Ubuntu 26.04, GCC 15, Release, lavapipe with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation):

    • on main, agc_driver_pm4_context_reg_rmw fails with opcode is not known in the reference;
    • with this PR, agc_driver_pm4 and agc_driver_pm4_context_reg_rmw pass 2/2;
    • no VUID- errors and no missing-layer warning.
  • Windows 11, RTX 3060: (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release, NVIDIA driver 610.88, Vulkan SDK 1.4.363, same validation environment):

    • all 17 agc_driver_pm4* tests pass at 6cec611cd0;
    • with main's Pm4.cpp and Pm4Opcodes.hpp, agc_driver_pm4_context_reg_rmw fails with opcode is not known in the reference, and agc_driver_pm4 with reference opcode catalog is incomplete;
    • no VUID- lines and no missing-layer warning in either run;
    • no compiler warnings in the changed files.

    The PM4 tests validate and execute packets on the CPU and create no Vulkan device. So the validation environment shows nothing breaks, but it doesn't exercise GPU validation.

  • Mutation check: dropping & mask on the data fails with CONTEXT_REG_RMW used data outside the mask.

  • python3 tools/check_conventions.py --base origin/main: all checks passed.

  • Overlap: trial merges with my #16184 (COND_WRITE) and #16345 (DMA_DATA GDS controls), which also edit Pm4.cpp and tests/Pm4.cpp, are clean. pr_overlap.py couldn't compare 12 PRs that conflict with main, so I read their diffs by hand: #6186, #6188, #6549, #7642, #9893, #10193, #10249, #13928, #13929, #14944, #15136 and #16751. They change other packets, memory handling or test registration; none adds CONTEXT_REG_RMW.

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 26300) and lavapipe (Mesa, Ubuntu 26.04); the PM4 tests are CPU-side and create no Vulkan device
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5205208443 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16878). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-07T19:42:32Z. --- ### What The PM4 packet `CONTEXT_REG_RMW` (type-3 opcode `0x51`) wasn't in the AGC driver's reference catalogue, so a command buffer containing it failed validation with `opcode is not known in the reference`. This PR implements it from PAL at c5e80007, the revision my #16184 (COND_WRITE) and #16345 (DMA_DATA) cite: - [`BuildContextRegRmw`](https://github.com/GPUOpen-Drivers/pal/blob/c5e800072a32f68b6ccc4422936d96167c6e0728/src/core/hw/gfxip/gfx9/gfx9CmdUtil.cpp#L2859-L2888); - [the packet definition](https://github.com/GPUOpen-Drivers/pal/blob/c5e800072a32f68b6ccc4422936d96167c6e0728/src/core/hw/gfxip/gfx9/chip/gfx9_plus_merged_f32_me_pm4_packets.h#L686-L721). The packet has four dwords: the header, the context-register offset (16 bits, upper 16 reserved), a mask and data. Its effect is `new = (old & ~mask) | (data & mask)`. PAL emits it for colour and depth state in `gfx9UniversalCmdBuffer.cpp`. - **Validation:** the packet is accepted only on graphics queues, as `SET_CONTEXT_REG` is. It must be exactly four dwords, and set reserved offset bits are rejected. - **Execution:** - it reads the old value from the modelled context-register state; - it writes the result through the same path `SET_CONTEXT_REG` uses, so later reads, `COPY_DATA` from the register and the register fingerprint all see it; - a register with no known value (never written, and no reset value in the model) throws instead of assuming zero. - **Catalogue:** the reference opcode catalogue grows from 56 to 57. - **Debt:** a `CONTEXT_REG_RMW` entry in `docs/dev/debt/libSceAgcDriver.md` records the throw for a register with no known value. Of the registers PAL modifies with this packet, `CB_COLORn_DCC_CONTROL`, `DB_COUNT_CONTROL` and `DB_RESERVED_REG_2` have no reset value in the model. Console behaviour is unmeasured, as for the other PM4 packets. ### Tested - **New test:** `agc_driver_pm4_context_reg_rmw` (also run inside `agc_driver_pm4`) covers: - preserved and replaced bits, and data bits outside the mask being ignored; - zero and full masks; - a fingerprint change, and a `COPY_DATA` readback of the register; - an RMW on a reset-state register; - packets that are too short or too long; - an unknown old value throwing; - compute-queue rejection; - reserved offset bits. - **Linux x86-64** (Ubuntu 26.04, GCC 15, Release, lavapipe with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`): - on `main`, `agc_driver_pm4_context_reg_rmw` fails with `opcode is not known in the reference`; - with this PR, `agc_driver_pm4` and `agc_driver_pm4_context_reg_rmw` pass 2/2; - no `VUID-` errors and no missing-layer warning. - **Windows 11, RTX 3060:** (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release, NVIDIA driver 610.88, Vulkan SDK 1.4.363, same validation environment): - all 17 `agc_driver_pm4*` tests pass at 6cec611cd0; - with `main`'s `Pm4.cpp` and `Pm4Opcodes.hpp`, `agc_driver_pm4_context_reg_rmw` fails with `opcode is not known in the reference`, and `agc_driver_pm4` with `reference opcode catalog is incomplete`; - no `VUID-` lines and no missing-layer warning in either run; - no compiler warnings in the changed files. The PM4 tests validate and execute packets on the CPU and create no Vulkan device. So the validation environment shows nothing breaks, but it doesn't exercise GPU validation. - **Mutation check:** dropping `& mask` on the data fails with `CONTEXT_REG_RMW used data outside the mask`. - `python3 tools/check_conventions.py --base origin/main`: all checks passed. - **Overlap:** trial merges with my #16184 (COND_WRITE) and #16345 (DMA_DATA GDS controls), which also edit `Pm4.cpp` and `tests/Pm4.cpp`, are clean. `pr_overlap.py` couldn't compare 12 PRs that conflict with `main`, so I read their diffs by hand: #6186, #6188, #6549, #7642, #9893, #10193, #10249, #13928, #13929, #14944, #15136 and #16751. They change other packets, memory handling or test registration; none adds `CONTEXT_REG_RMW`. ### 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 26300) and lavapipe (Mesa, Ubuntu 26.04); the PM4 tests are CPU-side and create no Vulkan device - [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!16878
No description provided.