graphics: hold HTile fast clears on depth-read-only passes #401

Closed
github-bot wants to merge 1 commit from gh-pr/401/head into gh-pr/401/base
Owner

@⁠brandostrong on GitHub · 2026-08-29 16:16 UTC · original
brandostrong:fix/htile-clear-depth-readonly → main · +4 −1 · 1 files · 1 commits · closed without merging

This is a huge improvement in GTA. It goes from 70% of the things in the scene not being drawn(no walls no ceiling, floor is invisible, no objects) to basically all of them.

Summary

  • Consume an armed HTile fast clear only on a pass that writes depth.
  • Leave the clear armed when the binding pass has depth writes disabled, so the next
    writing pass still receives it.
  • No change to passes that already write depth, including the clearing prepass.

Problem

HTile fast clears are emulated by recording that a depth surface is logically cleared,
then discharging that as a Vulkan loadOp = CLEAR on the next bind of the target. The
consume site tested only whether a clear was armed, never whether the binding pass
writes depth:

depth.depth_meta_clear_enable =
    depth.htile &&
    cache.IsMetaCleared(depth.htile_buffer_vaddr, depth.desc.view_info.base_layer);

A pass with Z_WRITE_ENABLE cleared only reads depth. Discharging the clear there
destroys the depth it is about to test against, so every fragment fails, no fragment
writes depth, and the surface stays at the clear value for the rest of the frame. On
hardware this cannot happen: the fast clear is a change to metadata state, not an
operation attached to a pass.

In GTA V (PPSA04264) the main scene depth target is cleared to 0.0 and written by a
GEQUAL prepass (reversed-Z), then bound by a read-only pass using LESS. That pass
consumed the clear, leaving the buffer uniformly 0.0:

[diag] depth=0x0246B40000 htile=0x0247E00000 2560x1440 clear=0.000000 test=1 write=1 func=GEQUAL load_clear=1
[diag] depth=0x0246B40000 htile=0x0247E00000 2560x1440 clear=0.000000 test=1 write=0 func=LESS   load_clear=1

A RenderDoc capture of the same frame showed the depth attachment uniformly 0.0 with
Func = Less, Write = off, and geometry rejected with "Depth test failed".

Implementation

  • Gate depth_meta_clear_enable on depth_write_enable in AcquireRenderTargets.
  • The existing TouchMeta(..., false) consume is already gated on the same flag, so a
    held clear stays armed rather than being silently discarded.

AI assistance

AI assistance was used because I'm a smooth brained javascript dev

**@⁠brandostrong** on GitHub · 2026-08-29 16:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/401) `brandostrong:fix/htile-clear-depth-readonly` → `main` · +4 −1 · 1 files · 1 commits · closed without merging This is a huge improvement in GTA. It goes from 70% of the things in the scene not being drawn(no walls no ceiling, floor is invisible, no objects) to basically all of them. ## Summary - Consume an armed HTile fast clear only on a pass that writes depth. - Leave the clear armed when the binding pass has depth writes disabled, so the next writing pass still receives it. - No change to passes that already write depth, including the clearing prepass. ## Problem HTile fast clears are emulated by recording that a depth surface is logically cleared, then discharging that as a Vulkan `loadOp = CLEAR` on the next bind of the target. The consume site tested only whether a clear was armed, never whether the binding pass writes depth: ```cpp depth.depth_meta_clear_enable = depth.htile && cache.IsMetaCleared(depth.htile_buffer_vaddr, depth.desc.view_info.base_layer); ``` A pass with `Z_WRITE_ENABLE` cleared only reads depth. Discharging the clear there destroys the depth it is about to test against, so every fragment fails, no fragment writes depth, and the surface stays at the clear value for the rest of the frame. On hardware this cannot happen: the fast clear is a change to metadata state, not an operation attached to a pass. In GTA V (PPSA04264) the main scene depth target is cleared to 0.0 and written by a GEQUAL prepass (reversed-Z), then bound by a read-only pass using LESS. That pass consumed the clear, leaving the buffer uniformly 0.0: ```text [diag] depth=0x0246B40000 htile=0x0247E00000 2560x1440 clear=0.000000 test=1 write=1 func=GEQUAL load_clear=1 [diag] depth=0x0246B40000 htile=0x0247E00000 2560x1440 clear=0.000000 test=1 write=0 func=LESS load_clear=1 ``` A RenderDoc capture of the same frame showed the depth attachment uniformly 0.0 with `Func = Less, Write = off`, and geometry rejected with "Depth test failed". ## Implementation - Gate `depth_meta_clear_enable` on `depth_write_enable` in `AcquireRenderTargets`. - The existing `TouchMeta(..., false)` consume is already gated on the same flag, so a held clear stays armed rather than being silently discarded. ## AI assistance AI assistance was used because I'm a smooth brained javascript dev
A pass with Z_WRITE_ENABLE cleared only tests against depth. Materializing an
armed HTile fast clear on such a pass discards the depth earlier passes wrote,
so every later test fails, nothing writes depth
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:19:05 +00:00
github-bot closed this pull request 2026-11-26 09:19:05 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.