graphics: do not arm a fast clear from a read-modify-write dispatch #428

Manually merged
github merged 2 commits from gh-pr/428/head into gh-pr/428/base 2026-11-26 09:20:23 +00:00
Owner

@⁠brandostrong on GitHub · 2026-08-31 19:35 UTC · original
brandostrong:fix/htile-rmw-not-a-clear → main · +109 −1 · 3 files · 2 commits · merged 2026-09-01 01:48 UTC

baseline-restored variantA

Problem

TryConsumeComputeMetaClear decides a compute dispatch is a metadata fast clear from coverage alone — it writes the whole metadata surface and contains no BitwiseXor32. It never checks that the dispatch is actually a fill.

GTA V runs a dispatch over the whole HTILE surface that reads each dword and writes back (d & 0xF) == 0 ? clear_word : d. d & 0xF is ZMASK, so it re-stamps only tiles that are already clear and preserves every tile that holds real depth. Treating it as a fast clear discards the dispatch and arms a full-surface depth clear, wiping g-buffer depth mid-frame — a pixel measured 0.02722705 before that pass and 0.0 after, so the distant sky plane (depth 6e-8, reverse-Z GEQUAL) then passed in front of the world. Every depth test after that point is affected, not only the sky.

A second dispatch on the same path is a genuine fill — four SGPRs stored with one BUFFER_STORE_FORMAT_XYZW — and must keep arming.

Change

Reject a dispatch that also reads the metadata surface it writes. A read-modify-write preserves existing contents by definition, so it cannot be a clear. BufferResource::read is already tracked, so this is one condition.

The DCC path already requires a validated fill value before treating a compute write as a clear; HTILE had no equivalent check.

Note the rejected dispatch now executes rather than being discarded.

AI assistance

Claude. It found the cause by disassembling the guest shader's recompiled SPIR-V and comparing it to emulator code, after we traced it by bisecting(enabling/disabling) the shaders to find the offending pass.

**@⁠brandostrong** on GitHub · 2026-08-31 19:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/428) `brandostrong:fix/htile-rmw-not-a-clear` → `main` · +109 −1 · 3 files · 2 commits · merged 2026-09-01 01:48 UTC <img width="1280" height="720" alt="baseline-restored" src="https://github.com/user-attachments/assets/64feb719-47d8-46c8-b133-f2a24e2386e6" /> <img width="1280" height="720" alt="variantA" src="https://github.com/user-attachments/assets/046b832a-71d3-4dee-ad33-ca954d554c7d" /> ## Problem `TryConsumeComputeMetaClear` decides a compute dispatch is a metadata fast clear from coverage alone — it writes the whole metadata surface and contains no `BitwiseXor32`. It never checks that the dispatch is actually a fill. GTA V runs a dispatch over the whole HTILE surface that reads each dword and writes back `(d & 0xF) == 0 ? clear_word : d`. `d & 0xF` is ZMASK, so it re-stamps only tiles that are already clear and preserves every tile that holds real depth. Treating it as a fast clear discards the dispatch and arms a full-surface depth clear, wiping g-buffer depth mid-frame — a pixel measured `0.02722705` before that pass and `0.0` after, so the distant sky plane (depth `6e-8`, reverse-Z `GEQUAL`) then passed in front of the world. Every depth test after that point is affected, not only the sky. A second dispatch on the same path is a genuine fill — four SGPRs stored with one `BUFFER_STORE_FORMAT_XYZW` — and must keep arming. ## Change Reject a dispatch that also reads the metadata surface it writes. A read-modify-write preserves existing contents by definition, so it cannot be a clear. `BufferResource::read` is already tracked, so this is one condition. The DCC path already requires a validated fill value before treating a compute write as a clear; HTILE had no equivalent check. Note the rejected dispatch now executes rather than being discarded. ## AI assistance Claude. It found the cause by disassembling the guest shader's recompiled SPIR-V and comparing it to emulator code, after we traced it by bisecting(enabling/disabling) the shaders to find the offending pass.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:20:20 +00:00
github manually merged commit 39c75feb98 into gh-pr/428/base 2026-11-26 09:20:23 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.