fix(agc): fast-clear the viewed mip of a 2D mipmapped DCC colour target #26046

Merged
klosixgaming-arch merged 7 commits from upstream-pr/26046 into main 2026-11-24 16:48:48 +00:00
klosixgaming-arch commented 2026-11-23 05:30:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-11-23T05:30:27Z.


What

On main, a 2D mipmapped DCC colour target never gets its viewed mip fast-cleared. DecodeColorBuffer keeps the chain's key base only in chainDccAddress and logs "DCC keys of mipmapped array and 3D color targets are ignored", so the target's image starts from whatever guest memory holds. When the game fast-clears such a target and then blends into it, the draw starts from stale bytes.

Cyberpunk 2077 (PPSA03974) hits this on "Set V's appearance" in the character creator: magenta and green noise over the bottom third of the screen. The 3200x1800 RGBA16F character preview (5 mips) shares its memory with 2400x1800 R32U and B10G11R11 targets drawn earlier in the frame. The preview's draws blend with ONE / ONE_MINUS_SRC_COLOR, so the 32-bit bytes left by those targets show through, and read as half floats they hold NaNs, which the composite turns into magenta.

This PR gives the viewed mip its own key range and serves its fast clear:

  • The viewed mip's keys are read at its offset in the chain's metadata, per AMD Addrlib Gfx10Lib::HwlComputeDccInfo: a 4096-key metadata block covers 1 MiB of texels (512x512 at 4 bytes, 512x256 at 8 bytes); with a mip tail, the tail levels share one block at offset 0; the levels above the tail follow from the smallest to mip 0.
  • When that slice holds one clear code, the mip is cleared on the GPU on the resident chain image: no CPU store of the mip, no re-upload. The slice's keys are marked uncompressed after the draw, and the write-back stores the mip whole, because its undrawn part is the clear, not the stored bytes.
  • When the game's key fill is still a recorded GPU write at bind (Cyberpunk re-issues its key fills every frame), the keys are answered from the recorded writes without a sync: a fill leaving one fillable clear code takes the GPU clear, recorded after the fill in the same queue; a fill of 0xff clears nothing; mixed, partial or unknown writers fall back to the current keys.
  • A viewed mip inside the mip tail reads the shared tail block and is not fast-cleared. Arrays and 3D targets keep the current behaviour and log line.
  • APS5_NO_DCC_MIP_FAST_CLEAR (a runtime switch, so APS5_AB can toggle it) turns this off.

#21479 imports a uniform DCC clear for single-level targets and leaves mips out; this PR covers the mipmapped colour-target chain. They don't overlap.

How it was found

A frame capture of "Set V's appearance" (#21931) replayed the band exactly. Zeroing the 3200x1800 preview at bind removed it, with every other pass running. The colour buffer registers set DCC_ENABLE with a key base that the driver parked, and in that key array the keys change from 0xff to the clear code at key 90112, which is mip 0's offset in the Addrlib layout for this chain (mips 4 to 1 take 1 + 1 + 4 + 16 blocks).

Tested

Setup: Ubuntu 26.04.1 (Linux 7.0.0-43), NVIDIA GeForce RTX 4080 (595.99.02), Xeon E5-2699 v3, GCC 15.2.0 Release. Based on main db397a73fe.

Unit tests:

  • agc_driver_dcc_keys_first_write gains the key offsets as a pure function (the 3200x1800 8-byte chain, a 1024x1024 4-byte chain and a 2048x1024 8-byte chain with tails, a tail level), a blended draw over a mipmapped target whose mip-0 keys hold a clear code over stale bytes, and three pending-fill cases (clear code, 0xff, partial). The pending clear-code case fails without the pending-fill change: the bind syncs the fill and stores the clear on the CPU.
  • DCC, mixed-key and runtime-switch tests: 10 of 10.
  • Full agc_ suite at 6d2124e4f4: 2033 of 2035 with -j8. The two failures, agc_driver_draw_cache_capacity and agc_driver_draw_shader_failure, pass when run on their own.

Cyberpunk 2077 PPSA03974, arms alternated, off = APS5_NO_DCC_MIP_FAST_CLEAR=1. Noise = magenta share of the bottom third, last 4 frames on "Set V's appearance".

boot fix "Set V's appearance" noise
on-1 on 0.00 / 0.00 / 0.00 / 0.00
off-1 off 25.21 / 17.00 / 17.30 / 17.20
on-2 on 0.00 / 0.00 / 0.00 / 0.00
off-2 off 17.24 / 17.08 / 17.36 / 17.29

Body Type is drawn in both arms. Intro, one warm-up per arm, then 3 boots per arm, presents per 10 s: on 56.4 / 58.4 / 56.0, off 57.8 / 56.5 / 56.1. No measurable cost.

Not verified: the layout is checked against one title's chain without a tail; the tail case rests on Addrlib alone. V is still a black silhouette on this screen with the fix on and off; that is a separate bug.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: PPSA03974 #8045
  • GPUs tested: NVIDIA GeForce RTX 4080, driver 595.99.02, Ubuntu 26.04.1
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5447670252 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26046). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-11-23T05:30:27Z. --- ### What On `main`, a 2D mipmapped DCC colour target never gets its viewed mip fast-cleared. `DecodeColorBuffer` keeps the chain's key base only in `chainDccAddress` and logs "DCC keys of mipmapped array and 3D color targets are ignored", so the target's image starts from whatever guest memory holds. When the game fast-clears such a target and then blends into it, the draw starts from stale bytes. Cyberpunk 2077 (PPSA03974) hits this on "Set V's appearance" in the character creator: magenta and green noise over the bottom third of the screen. The 3200x1800 RGBA16F character preview (5 mips) shares its memory with 2400x1800 R32U and B10G11R11 targets drawn earlier in the frame. The preview's draws blend with ONE / ONE_MINUS_SRC_COLOR, so the 32-bit bytes left by those targets show through, and read as half floats they hold NaNs, which the composite turns into magenta. This PR gives the viewed mip its own key range and serves its fast clear: - The viewed mip's keys are read at its offset in the chain's metadata, per AMD Addrlib `Gfx10Lib::HwlComputeDccInfo`: a 4096-key metadata block covers 1 MiB of texels (512x512 at 4 bytes, 512x256 at 8 bytes); with a mip tail, the tail levels share one block at offset 0; the levels above the tail follow from the smallest to mip 0. - When that slice holds one clear code, the mip is cleared on the GPU on the resident chain image: no CPU store of the mip, no re-upload. The slice's keys are marked uncompressed after the draw, and the write-back stores the mip whole, because its undrawn part is the clear, not the stored bytes. - When the game's key fill is still a recorded GPU write at bind (Cyberpunk re-issues its key fills every frame), the keys are answered from the recorded writes without a sync: a fill leaving one fillable clear code takes the GPU clear, recorded after the fill in the same queue; a fill of `0xff` clears nothing; mixed, partial or unknown writers fall back to the current keys. - A viewed mip inside the mip tail reads the shared tail block and is not fast-cleared. Arrays and 3D targets keep the current behaviour and log line. - `APS5_NO_DCC_MIP_FAST_CLEAR` (a runtime switch, so `APS5_AB` can toggle it) turns this off. #21479 imports a uniform DCC clear for single-level targets and leaves mips out; this PR covers the mipmapped colour-target chain. They don't overlap. ### How it was found A frame capture of "Set V's appearance" (#21931) replayed the band exactly. Zeroing the 3200x1800 preview at bind removed it, with every other pass running. The colour buffer registers set DCC_ENABLE with a key base that the driver parked, and in that key array the keys change from `0xff` to the clear code at key 90112, which is mip 0's offset in the Addrlib layout for this chain (mips 4 to 1 take 1 + 1 + 4 + 16 blocks). ### Tested **Setup:** Ubuntu 26.04.1 (Linux 7.0.0-43), NVIDIA GeForce RTX 4080 (595.99.02), Xeon E5-2699 v3, GCC 15.2.0 Release. Based on `main` `db397a73fe`. Unit tests: - `agc_driver_dcc_keys_first_write` gains the key offsets as a pure function (the 3200x1800 8-byte chain, a 1024x1024 4-byte chain and a 2048x1024 8-byte chain with tails, a tail level), a blended draw over a mipmapped target whose mip-0 keys hold a clear code over stale bytes, and three pending-fill cases (clear code, `0xff`, partial). The pending clear-code case fails without the pending-fill change: the bind syncs the fill and stores the clear on the CPU. - DCC, mixed-key and runtime-switch tests: 10 of 10. - Full `agc_` suite at `6d2124e4f4`: 2033 of 2035 with `-j8`. The two failures, `agc_driver_draw_cache_capacity` and `agc_driver_draw_shader_failure`, pass when run on their own. Cyberpunk 2077 PPSA03974, arms alternated, `off` = `APS5_NO_DCC_MIP_FAST_CLEAR=1`. Noise = magenta share of the bottom third, last 4 frames on "Set V's appearance". | boot | fix | "Set V's appearance" noise | |---|---|---| | on-1 | on | 0.00 / 0.00 / 0.00 / 0.00 | | off-1 | off | 25.21 / 17.00 / 17.30 / 17.20 | | on-2 | on | 0.00 / 0.00 / 0.00 / 0.00 | | off-2 | off | 17.24 / 17.08 / 17.36 / 17.29 | Body Type is drawn in both arms. Intro, one warm-up per arm, then 3 boots per arm, presents per 10 s: on 56.4 / 58.4 / 56.0, off 57.8 / 56.5 / 56.1. No measurable cost. Not verified: the layout is checked against one title's chain without a tail; the tail case rests on Addrlib alone. V is still a black silhouette on this screen with the fix on and off; that is a separate bug. ### Checklist - [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) and the licence notice of code adapted from upstream (see AGENTS.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: PPSA03974 #8045 - [x] GPUs tested: NVIDIA GeForce RTX 4080, driver 595.99.02, Ubuntu 26.04.1 - [x] AI-assisted: yes
MarcZX10 commented 2026-11-23 05:56:56 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this change; the reported full-suite failures are described as passing when run individually, and the tail-layout limitation is documented.

What I ran

Reviewed head 6d2124e4f4aaf4467850cffb2b58c04cca00044f against the prepared diff; I did not run commands or tests.

Results

Check Result Note
Diff and source review passed Targeted paths and changed lines inspected
Programmatic checks not run No commands run

Findings

Blocking

None.

Non-blocking

None.

Not verified

No test suite or precheck was run. Reviewed changed-line content for DccMetadata.hpp, DccMetadata.cpp, Draw.cpp, RuntimeSwitches.cpp, State.cpp, Texture.cpp (targeted ranges via repo_read.py), DccKeysFirstWrite.cpp, ENVIRONMENT.md, and libSceAgcDriver.md. Texture.hpp and RuntimeSwitches.hpp were present in the review bundle but their changed lines were not read; Texture.cpp was excluded from the bundle for size and read through the repository reader. No changed file was excluded by the manifest other than Texture.cpp from the bundle.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6017139671 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26046#pullrequestreview-6017139671). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T05:56:56Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this change; the reported full-suite failures are described as passing when run individually, and the tail-layout limitation is documented. ## What I ran Reviewed head `6d2124e4f4aaf4467850cffb2b58c04cca00044f` against the prepared diff; I did not run commands or tests. ## Results | Check | Result | Note | |---|---|---| | Diff and source review | passed | Targeted paths and changed lines inspected | | Programmatic checks | not run | No commands run | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No test suite or precheck was run. Reviewed changed-line content for `DccMetadata.hpp`, `DccMetadata.cpp`, `Draw.cpp`, `RuntimeSwitches.cpp`, `State.cpp`, `Texture.cpp` (targeted ranges via `repo_read.py`), `DccKeysFirstWrite.cpp`, `ENVIRONMENT.md`, and `libSceAgcDriver.md`. `Texture.hpp` and `RuntimeSwitches.hpp` were present in the review bundle but their changed lines were not read; `Texture.cpp` was excluded from the bundle for size and read through the repository reader. No changed file was excluded by the manifest other than `Texture.cpp` from the bundle. ## To get this to a good state Nothing is required.
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!26046
No description provided.