feat(agc): apply the color logic operation of CB_COLOR_CONTROL #9348

Merged
klosixgaming-arch merged 3 commits from upstream-pr/9348 into main 2026-10-24 17:36:04 +00:00
klosixgaming-arch commented 2026-10-21 19:04:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-21T19:04:37Z.


What

CB_COLOR_CONTROL carries a ROP3 code in bits 16 to 23. The driver accepted only the copy code (0xcc) and threw for every other one, so a draw that asks for a color logic operation stopped the process. The code is now decoded into the draw state (State::colorRop), keyed in the pipeline cache key and in the pipeline journal, and applied through the Vulkan logic operation of the color blend state. The device enables the logicOp feature when it has it.

Cyberpunk 2077 (PPSA03974) stops with this about 31 minutes into a session, after character creation:
AGC graphics: only normal color rendering with copy ROP is supported (CB_COLOR_CONTROL 0x005a0010, mode normal)
ROP3 0x5a with mode normal.

Reading of the code: CB_COLOR_CONTROL.ROP3 takes 28 codes, in two forms: source and destination (pqrspqrs, 0xcc is copy) or brush and destination (pqpqrsrs, the brush is the shader color), as the R6xx 3D register reference describes the field and Mesa's ROP3 enum lists (both quoted by wachi35676 in this PR; I could not open them myself). In both forms bits 7:6 and 1:0 hold the same function, so LogicOpFromRop reads bits 0, 1, 6 and 7. That makes 0xcc copy, 0x66 and 0x5a XOR, 0x88 and 0xa0 AND, 0xee and 0xfa OR.

Throws rather than guessing:

  • a code that combines source and brush (outside the 28)
  • a logic operation together with blending on any color export
  • a device without the logicOp feature
  • a logic operation on a color target that is not an allowlisted normalized or integer format (sRGB, floating-point and packed-float targets throw)

The pipeline journal file format moves from 6 to 7 because the state it stores gains a field. #8365 and #8542 change the line that holds that constant, so whichever of them merges second needs a trivial rebase.

Tested

Windows 11 (10.0.26200), NVIDIA GeForce RTX 5090, driver 617.42, WinLibs GCC 15.2.0, Release, on main a6646f846. Vulkan validation layer 1.4.363 (VK_LAYER_KHRONOS_validation, inserted for the instance in the run), ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1.

  • New agc_driver_color_logic_op (tests/execution/ColorLogicOp.cpp): fills a 64x16 R8G8B8A8 target with a byte pattern, draws a covering triangle that exports (0.2, 0.4, 0.6, 0.8) (bytes 0x33, 0x66, 0x99, 0xcc) with ROP 0xcc, 0x5a, 0x88, 0xee and 0xcc again, and checks every byte against copy, XOR, AND, OR and copy. Passes. It skips on a device without logicOp.
  • agc_driver_graphics: new decode cases (0x5a0010 decodes to colorRop 0x5a and VK_LOGIC_OP_XOR, the copy code decodes as copy, fourteen ROP3 codes map to the expected operation, exactly 28 of the 256 codes are accepted, 0x5b is refused, a logic operation with blending throws). Passes. The existing check that CB_COLOR_CONTROL 0xcc0013 is refused with "copy ROP" still passes.
  • Neighbouring tests that build pipelines with the default state: agc_driver_color1555_target, agc_driver_packed_unorm_color_target, agc_driver_dual_source_blend, agc_driver_reversed_order_blend. All pass.
  • With the validation layer: agc_driver_graphics, agc_driver_color_logic_op, agc_driver_color1555_target and agc_driver_dual_source_blend produced 0 VUID-.
  • On main the new tests cannot be built because State::colorRop does not exist. What main does with the draw is the message above, taken from the game log.
  • Also agc_pipeline_journal, agc_pipeline_journal_long_paths and agc_pipeline_journal_extended_paths (journal format 7): pass.
  • python tools/check_conventions.py --base origin/main: passed.

I have not run the game on this build yet, so I do not claim it gets past the stop in the title or that the XOR output looks right there; the tests show the logic operation is applied to the target bytes as specified.

Checklist

  • Based on current main; no other open PR implements the same functions (the overlap check lists file overlaps only)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; the assumption about the ROP3 reading is listed in the library's technical debt file
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA03974 (not yet confirmed on the title)
  • GPUs tested: NVIDIA GeForce RTX 5090, driver 617.42, Windows 11 10.0.26200
  • AI-assisted: yes

AI-assisted: yes. Written with AI assistance and reviewed by me.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4956877484 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9348). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-21T19:04:37Z. --- ### What `CB_COLOR_CONTROL` carries a ROP3 code in bits 16 to 23. The driver accepted only the copy code (0xcc) and threw for every other one, so a draw that asks for a color logic operation stopped the process. The code is now decoded into the draw state (`State::colorRop`), keyed in the pipeline cache key and in the pipeline journal, and applied through the Vulkan logic operation of the color blend state. The device enables the `logicOp` feature when it has it. Cyberpunk 2077 (PPSA03974) stops with this about 31 minutes into a session, after character creation: `AGC graphics: only normal color rendering with copy ROP is supported (CB_COLOR_CONTROL 0x005a0010, mode normal)` ROP3 0x5a with mode normal. Reading of the code: `CB_COLOR_CONTROL.ROP3` takes 28 codes, in two forms: source and destination (`pqrspqrs`, 0xcc is copy) or brush and destination (`pqpqrsrs`, the brush is the shader color), as the R6xx 3D register reference describes the field and Mesa's `ROP3` enum lists (both quoted by wachi35676 in this PR; I could not open them myself). In both forms bits 7:6 and 1:0 hold the same function, so `LogicOpFromRop` reads bits 0, 1, 6 and 7. That makes 0xcc copy, 0x66 and 0x5a XOR, 0x88 and 0xa0 AND, 0xee and 0xfa OR. Throws rather than guessing: - a code that combines source and brush (outside the 28) - a logic operation together with blending on any color export - a device without the `logicOp` feature - a logic operation on a color target that is not an allowlisted normalized or integer format (sRGB, floating-point and packed-float targets throw) The pipeline journal file format moves from 6 to 7 because the state it stores gains a field. #8365 and #8542 change the line that holds that constant, so whichever of them merges second needs a trivial rebase. ### Tested Windows 11 (10.0.26200), NVIDIA GeForce RTX 5090, driver 617.42, WinLibs GCC 15.2.0, Release, on `main` a6646f846. Vulkan validation layer 1.4.363 (`VK_LAYER_KHRONOS_validation`, inserted for the instance in the run), `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`. - New `agc_driver_color_logic_op` (`tests/execution/ColorLogicOp.cpp`): fills a 64x16 R8G8B8A8 target with a byte pattern, draws a covering triangle that exports (0.2, 0.4, 0.6, 0.8) (bytes 0x33, 0x66, 0x99, 0xcc) with ROP 0xcc, 0x5a, 0x88, 0xee and 0xcc again, and checks every byte against copy, XOR, AND, OR and copy. Passes. It skips on a device without `logicOp`. - `agc_driver_graphics`: new decode cases (0x5a0010 decodes to `colorRop` 0x5a and `VK_LOGIC_OP_XOR`, the copy code decodes as copy, fourteen ROP3 codes map to the expected operation, exactly 28 of the 256 codes are accepted, 0x5b is refused, a logic operation with blending throws). Passes. The existing check that `CB_COLOR_CONTROL` 0xcc0013 is refused with "copy ROP" still passes. - Neighbouring tests that build pipelines with the default state: `agc_driver_color1555_target`, `agc_driver_packed_unorm_color_target`, `agc_driver_dual_source_blend`, `agc_driver_reversed_order_blend`. All pass. - With the validation layer: `agc_driver_graphics`, `agc_driver_color_logic_op`, `agc_driver_color1555_target` and `agc_driver_dual_source_blend` produced 0 `VUID-`. - On `main` the new tests cannot be built because `State::colorRop` does not exist. What `main` does with the draw is the message above, taken from the game log. - Also `agc_pipeline_journal`, `agc_pipeline_journal_long_paths` and `agc_pipeline_journal_extended_paths` (journal format 7): pass. - `python tools/check_conventions.py --base origin/main`: passed. I have not run the game on this build yet, so I do not claim it gets past the stop in the title or that the XOR output looks right there; the tests show the logic operation is applied to the target bytes as specified. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (the overlap check lists file overlaps only) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; the assumption about the ROP3 reading is listed in the library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: PPSA03974 (not yet confirmed on the title) - [x] GPUs tested: NVIDIA GeForce RTX 5090, driver 617.42, Windows 11 10.0.26200 - [x] AI-assisted: yes AI-assisted: yes. Written with AI assistance and reviewed by me.
wachi35676 commented 2026-10-21 22:59:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-21T22:59:30Z.


AMD run and a source for the ROP3 reading. Head b142ad1f merged onto main a6dcea927 (clean merge, 9cf202581).

Host: Windows 11 (10.0.26300), Ryzen 5 9600X, WinLibs GCC 15.2.0, Release. GPUs: NVIDIA RTX 5070 Ti (617.42) and AMD Radeon RDNA2 iGPU 1002:13c0 (proprietary 32.0.21042.62, ANYPS5_GPU=AMD). ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, no validation layer.

  • agc_driver_color_logic_op passes on both GPUs, with GPL and with APS5_NO_GPL=1. The AMD device exposes logicOp, so the test runs on AMD rather than skipping.
  • Negative control: with only blend.logicOpEnable = VK_TRUE changed to VK_FALSE in Pipeline.cpp, the test fails on both GPUs with ROP3 0x5a into an 8_8_8_8 unorm target: pixel (0, 0) channel 0 is 51, expected 56. 51 is the copied source byte 0x33.
  • 82-test related set (agc_driver_graphics*, the color-target, blend and pipeline-journal tests including agc_pipeline_journal* after the format 6→7 bump, mesh, indirect and others): the results match main on both GPUs. The only failures are main's existing local ones (image_array_window_past_layer_limit does not build under MinGW; agc_driver_tessellation fails on AMD).
  • tools/check_conventions.py --base a6dcea927 passes.

On the reading of the code ("no register documentation confirms the pattern operand is the source color"):

  • AMD's R6xx 3D register reference (x.org docs/AMD/old/R6xx_3D_Registers.pdf), CB_COLOR_CONTROL.ROP3 [23:16], says: "This field supports the 28 boolean ops that combine either source and dest or brush and dest, with brush provided by the shader in place of source. ROP3 codes that use both src and brush are emulated in software. Allowed ROP3 codes have either the form pqrspqrs (for source/dest ops) or pqpqrsrs (for brush/dest ops). The code 0xCC (11001100) copies the source to the destination". 0x5a (01011010) has the brush/dest form, so it is brush XOR dest, and the brush is the shader color.
  • Mesa's src/amd/registers/gfx10.json ROP3 enum has exactly those 28 values: 16 named source/dest codes (0x66 XOR, 0x88 AND, …) and 12 X_0X.. codes (0x05, 0x0a, 0x0f, 0x50, 0x5a, 0x5f, 0xa0, 0xa5, 0xaf, 0xf0, 0xf5, 0xfa), which are the brush/dest functions. radeonsi writes func | func << 4 (si_state.c) and RADV writes the V_028808_ROP3_* values.
  • For both allowed forms, bits 7:6 and 1:0 hold the same function, so LogicOpFromRop's index from bits 0, 1, 6 and 7 gives the same VkLogicOp whether the code is the source or the brush form. The table also matches Mesa's PIPE_LOGICOP order. The debt line could cite this instead of saying no documentation exists. A code that uses both src and brush (outside both forms) is "emulated in software" on the console. The PR maps such codes as if brush were source. Throwing on codes outside the two forms might be safer.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6328443120 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9348#issuecomment-6328443120). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-21T22:59:30Z. --- AMD run and a source for the ROP3 reading. Head `b142ad1f` merged onto main `a6dcea927` (clean merge, `9cf202581`). Host: Windows 11 (10.0.26300), Ryzen 5 9600X, WinLibs GCC 15.2.0, Release. GPUs: NVIDIA RTX 5070 Ti (617.42) and AMD Radeon RDNA2 iGPU `1002:13c0` (proprietary 32.0.21042.62, `ANYPS5_GPU=AMD`). `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`, no validation layer. - `agc_driver_color_logic_op` passes on both GPUs, with GPL and with `APS5_NO_GPL=1`. The AMD device exposes `logicOp`, so the test runs on AMD rather than skipping. - Negative control: with only `blend.logicOpEnable = VK_TRUE` changed to `VK_FALSE` in `Pipeline.cpp`, the test fails on both GPUs with `ROP3 0x5a into an 8_8_8_8 unorm target: pixel (0, 0) channel 0 is 51, expected 56`. 51 is the copied source byte 0x33. - 82-test related set (`agc_driver_graphics*`, the color-target, blend and pipeline-journal tests including `agc_pipeline_journal*` after the format 6→7 bump, mesh, indirect and others): the results match main on both GPUs. The only failures are main's existing local ones (`image_array_window_past_layer_limit` does not build under MinGW; `agc_driver_tessellation` fails on AMD). - `tools/check_conventions.py --base a6dcea927` passes. On the reading of the code ("no register documentation confirms the pattern operand is the source color"): - AMD's R6xx 3D register reference (x.org `docs/AMD/old/R6xx_3D_Registers.pdf`), `CB_COLOR_CONTROL.ROP3` [23:16], says: "This field supports the 28 boolean ops that combine either source and dest or brush and dest, with brush provided by the shader in place of source. ROP3 codes that use both src and brush are emulated in software. Allowed ROP3 codes have either the form pqrspqrs (for source/dest ops) or pqpqrsrs (for brush/dest ops). The code 0xCC (11001100) copies the source to the destination". 0x5a (`01011010`) has the brush/dest form, so it is brush XOR dest, and the brush is the shader color. - Mesa's `src/amd/registers/gfx10.json` `ROP3` enum has exactly those 28 values: 16 named source/dest codes (0x66 XOR, 0x88 AND, …) and 12 `X_0X..` codes (0x05, 0x0a, 0x0f, 0x50, 0x5a, 0x5f, 0xa0, 0xa5, 0xaf, 0xf0, 0xf5, 0xfa), which are the brush/dest functions. radeonsi writes `func | func << 4` (`si_state.c`) and RADV writes the `V_028808_ROP3_*` values. - For both allowed forms, bits 7:6 and 1:0 hold the same function, so `LogicOpFromRop`'s index from bits 0, 1, 6 and 7 gives the same `VkLogicOp` whether the code is the source or the brush form. The table also matches Mesa's `PIPE_LOGICOP` order. The debt line could cite this instead of saying no documentation exists. A code that uses both src and brush (outside both forms) is "emulated in software" on the console. The PR maps such codes as if brush were source. Throwing on codes outside the two forms might be safer. AI-assisted: yes (Claude Code); results above were run on this machine.
MarcZX10 commented 2026-10-23 05:11:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T05:11:38Z.

Review: APPROVED


Reviewed exact head 191dddae77. The ROP3 decoding is confined to the documented source/brush forms; pipeline state, cache key, register decode key, and journal codec all include the operation, and unsupported blend/format/device combinations fail explicitly. The added tests exercise the logic-op byte results, code mapping/refusal, and journal format; the PR reports zero Vulkan validation VUIDs on the listed Windows/NVIDIA runs. Local diff check, conventions, and test-registration checks pass. I could not run the AGC executable in this host: the available older AnyPS5 test binary aborts before startup because this CPU lacks required x86 extensions. The PR reports the new tests cannot be built on main because State::colorRop is absent there; hosted product jobs are skipped. The Cyberpunk title behavior remains unverified, as the PR states.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5624160185 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9348#pullrequestreview-5624160185). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T05:11:38Z. **Review:** APPROVED --- Reviewed exact head 191dddae7764d97d58faf9bd6e71b602acaadaa0. The ROP3 decoding is confined to the documented source/brush forms; pipeline state, cache key, register decode key, and journal codec all include the operation, and unsupported blend/format/device combinations fail explicitly. The added tests exercise the logic-op byte results, code mapping/refusal, and journal format; the PR reports zero Vulkan validation VUIDs on the listed Windows/NVIDIA runs. Local diff check, conventions, and test-registration checks pass. I could not run the AGC executable in this host: the available older AnyPS5 test binary aborts before startup because this CPU lacks required x86 extensions. The PR reports the new tests cannot be built on main because `State::colorRop` is absent there; hosted product jobs are skipped. The Cyberpunk title behavior remains unverified, as the PR states.
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!9348
No description provided.