fix(agc): draw with DB_RENDER_CONTROL STENCIL_CLEAR_ENABLE #1479

Closed
Aryansh1520 wants to merge 1 commit from upstream-pr/1479 into main
Aryansh1520 commented 2026-10-08 08:53:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-08T08:53:54Z.


What

A draw with DB_RENDER_CONTROL STENCIL_CLEAR_ENABLE (bit 1) was rejected as a whole by the state decoder, so its color output was dropped together with the stencil clear.

PPSA28997 (God of War Sons of Sparta) starts every frame with such a draw (DB_RENDER_CONTROL = 0x22) that also writes the background into its 3840x2160 B10G11R11 scene target. With the draw skipped, the target was never reset, and the title's DST_COLOR/ONE light sprites multiplied the previous frame's values until they saturated: white areas that grew from moving lit sprites and never faded. Because [gpu] skipped draw is reported once per reason, the per-frame skip showed up only once in the log.

The draw is now rasterized like any other, with the stencil state of both faces replaced by: compare ALWAYS, fail/pass/depth-fail REPLACE, compare and write masks 0xff, reference DB_STENCIL_CLEAR. Every covered sample takes the clear value whatever the stencil and depth tests are, and the color outputs are written as usual. The depth/stencil state is decoded for such a draw even when DB_DEPTH_CONTROL enables no test. Depth clear, copy, resummarize and decompress (0x00001f9d) are still rejected.

Related: #1395 recognizes depth/stencil clear draws as image clears and is blocked on proving that a draw covers the surface. This change rasterizes the draw instead, so only covered samples are cleared and the draw's color output is kept; it covers the stencil clear only.

Tested

  • Linux (CachyOS, kernel 7.2), GCC, NVIDIA RTX 5060 Laptop GPU: PPSA28997 title screen and gameplay render correctly; before the change the white areas covered most of the screen within about 30 s on both the RTX 5060 and the integrated Radeon 780M.
  • agc_driver_graphics passes with two new cases in DepthStencilTests (stencil clear with and without a stencil test in DB_DEPTH_CONTROL); both fail without the change.
  • tools/check_conventions.py --base origin/main passes.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4784294593 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1479). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-08T08:53:54Z. --- ### What A draw with `DB_RENDER_CONTROL` `STENCIL_CLEAR_ENABLE` (bit 1) was rejected as a whole by the state decoder, so its color output was dropped together with the stencil clear. PPSA28997 (God of War Sons of Sparta) starts every frame with such a draw (`DB_RENDER_CONTROL = 0x22`) that also writes the background into its 3840x2160 B10G11R11 scene target. With the draw skipped, the target was never reset, and the title's `DST_COLOR`/`ONE` light sprites multiplied the previous frame's values until they saturated: white areas that grew from moving lit sprites and never faded. Because `[gpu] skipped draw` is reported once per reason, the per-frame skip showed up only once in the log. The draw is now rasterized like any other, with the stencil state of both faces replaced by: compare `ALWAYS`, fail/pass/depth-fail `REPLACE`, compare and write masks `0xff`, reference `DB_STENCIL_CLEAR`. Every covered sample takes the clear value whatever the stencil and depth tests are, and the color outputs are written as usual. The depth/stencil state is decoded for such a draw even when `DB_DEPTH_CONTROL` enables no test. Depth clear, copy, resummarize and decompress (`0x00001f9d`) are still rejected. Related: #1395 recognizes depth/stencil clear draws as image clears and is blocked on proving that a draw covers the surface. This change rasterizes the draw instead, so only covered samples are cleared and the draw's color output is kept; it covers the stencil clear only. ### Tested - Linux (CachyOS, kernel 7.2), GCC, NVIDIA RTX 5060 Laptop GPU: PPSA28997 title screen and gameplay render correctly; before the change the white areas covered most of the screen within about 30 s on both the RTX 5060 and the integrated Radeon 780M. - `agc_driver_graphics` passes with two new cases in `DepthStencilTests` (stencil clear with and without a stencil test in `DB_DEPTH_CONTROL`); both fail without the change. - `tools/check_conventions.py --base origin/main` passes. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
NahuelGenchi commented 2026-10-09 05:15:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-09T05:15:13Z.


Sonic Origins (PPSA05324) clears with draws too. The first has DB_RENDER_CONTROL 0x3, then repeated 0x1, with DB_DEPTH_CLEAR 0.0, DB_DEPTH_CONTROL 0x777 and no pixel program (#2022 lets those through the precheck). This PR covers the stencil half.

I have the depth half (bit 0) ready on a branch: the depth compare forced to ALWAYS with writes on, and the viewport depth range pinned to DB_DEPTH_CLEAR, with a TechnicalDebt entry since that is inferred, not measured. It changes the same DB_RENDER_CONTROL mask and the same decodeDepth condition as this PR. Would you rather take it in here, or should I open it as a follow-up on top of this one?

Bring-up thread: #2021

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074767599 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1479#issuecomment-6074767599). Originally posted by [NahuelGenchi](https://github.com/NahuelGenchi) on 2026-10-09T05:15:13Z. --- Sonic Origins (PPSA05324) clears with draws too. The first has `DB_RENDER_CONTROL` 0x3, then repeated 0x1, with `DB_DEPTH_CLEAR` 0.0, `DB_DEPTH_CONTROL` 0x777 and no pixel program (#2022 lets those through the precheck). This PR covers the stencil half. I have the depth half (bit 0) ready on a branch: the depth compare forced to ALWAYS with writes on, and the viewport depth range pinned to `DB_DEPTH_CLEAR`, with a TechnicalDebt entry since that is inferred, not measured. It changes the same `DB_RENDER_CONTROL` mask and the same `decodeDepth` condition as this PR. Would you rather take it in here, or should I open it as a follow-up on top of this one? Bring-up thread: #2021
Aryansh1520 commented 2026-10-09 05:28:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-09T05:28:35Z.


Thanks for checking it against Sonic Origins. Please open the depth half as its own PR on top of this one, with Depends on #1479, since CONTRIBUTING asks for follow-ups in a new PR and it keeps the inferred depth behaviour reviewable separately. I'll keep the DB_RENDER_CONTROL mask and the decodeDepth condition here as they are so your branch rebases cleanly; if this needs changes in review I'll mention you.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074914740 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1479#issuecomment-6074914740). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-09T05:28:35Z. --- Thanks for checking it against Sonic Origins. Please open the depth half as its own PR on top of this one, with `Depends on #1479`, since CONTRIBUTING asks for follow-ups in a new PR and it keeps the inferred depth behaviour reviewable separately. I'll keep the `DB_RENDER_CONTROL` mask and the `decodeDepth` condition here as they are so your branch rebases cleanly; if this needs changes in review I'll mention you.
oneandonlydean commented 2026-10-09 08:56:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T08:56:14Z.


Closing in favour of #1534, which carries this commit with your authorship and adds the two missing guards: a read-only or absent stencil plane throws, and the clear is applied before the ordinary stencil ops are decoded. The depth half can go on top of #1534 instead.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077726876 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1479#issuecomment-6077726876). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T08:56:14Z. --- Closing in favour of #1534, which carries this commit with your authorship and adds the two missing guards: a read-only or absent stencil plane throws, and the clear is applied before the ordinary stencil ops are decoded. The depth half can go on top of #1534 instead.

Pull request closed

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!1479
No description provided.