Skip to content

GS/HW: Support for integer depth.#13854

Draft
TJnotJT wants to merge 14 commits into
PCSX2:masterfrom
TJnotJT:gs-hw-int-depth
Draft

GS/HW: Support for integer depth.#13854
TJnotJT wants to merge 14 commits into
PCSX2:masterfrom
TJnotJT:gs-hw-int-depth

Conversation

@TJnotJT
Copy link
Copy Markdown
Contributor

@TJnotJT TJnotJT commented Jan 18, 2026

Status: this is a WIP for early testing. There are several performance and code cleanup issues to be addressed. Committed on top of ROV, but has not been fully tested.

Description of Changes

Adds support for integer depth format to DX12/VK/GL/DX11.

Procedure for interpolating 32 bit Z values was given by @TellowKrinkle:

  1. In the vertex shader send the minimum Z value of each triangle as a flat uint attribute, along with the offset as an interpolated float attribute.
  2. In the fragment shader add the flat minimum value to the interpolated float value.

This should work as long as each triangle's Z range fits in 24 bits (which appears to be the case in all GS dumps examined so far).

Rationale behind Changes

Makes depth accuracy about the same as SW when the full 32 bit range is used non-trivially (i.e., upper bits of depth take multiple values). I don't know of many cases where this is actually needed, so this is more of a "nice to have" feature. It comes at a significant performance cost, so a less expensive fix is preferable (Z floor and/or limit 24 bit setting) unless absolutely required.

Draws with integer depth will usually require full barriers since we need to read/write the buffer for depth testing. This might be impractical in many cases, though it could be more usable when combined with ROVs.

Suggested Testing Steps

Use the following setting in the INI:

[EmuCore/GS]
HWZIntegerMode = 1

The values are:

  • HWZIntegerMode = 0: Disabled.
  • HWZIntegerMode = 1: Enabled. Use integer depth when the Z values go outside the 24 bit range and switch back to regular depth if the range goes back.
  • HWZIntegerMode = 2: Always. Always use integer depth. This is more more testing than for practical use.
    Then use VK and/or DX12.

Example

The only case I know where 32 bit Z is used non-trivially (thanks @refractionpcsx2 ):

Shox_SLUS-20533_20260111064920.gs.xz (see the signs in the distance and sides of the road)

Master VK
03186_f00023_fr-1_00000_C_16_master

Master SW
03186_f00023_fr-1_00000_C_16_sw

PR VK
03186_f00023_fr-1_00000_C_16_pr

Did you use AI to help find, test, or implement this issue or feature?

Yes, to get help with the API usage/shader programming and info about extensions. Also, for reviewing the 64 bit arithmetic code.

@MarioSonic2987
Copy link
Copy Markdown

MarioSonic2987 commented Jan 18, 2026

Fixes z-fighting in the following games without using the Limit Depth to 24 bits hack:

Harry Potter and the Goblet of Fire

Before:
image

After:
image

It no longer breaks the graphics in this cutscene (see #13805 (comment)):
image

Worms 3D

Before:
image

After:
image

Worms Forts: Under Siege

Before:
image

After:
image

Worms 4 Mayhem

Before:
image

After:
image

@bigol83
Copy link
Copy Markdown

bigol83 commented Jan 18, 2026

Does this include the recent zfighting fixes that are in master? If it does this breaks those, with a couple of games i tested it went back to big zfighting just like it was before zfighting recent fixes were merged.

gsdump
https://www.swisstransfer.com/d/b80a8856-b700-4d3b-a656-182c69e1eef6

@TJnotJT
Copy link
Copy Markdown
Contributor Author

TJnotJT commented Jan 18, 2026

Kingdom Hearts II - It needs HWZIntegerMode set to 2. If not, z-fighting strikes back.

In theory there should be no difference between mode 1 and 2 so this might be a bug. Would it be possible to have a dump showing this?

Does this include the recent zfighting fixes that are in master? If it does this breaks those, with a couple of games i tested it went back to big zfighting just like it was before zfighting recent fixes were merged.

Yes, there was a rebase error with Z floor in VK that is hopefully fixed on the last push.

@MarioSonic2987
Copy link
Copy Markdown

There's no z-fighting anymore in KH2 with HWZIntegerMode = 1.
image

GS Dump

@bigol83
Copy link
Copy Markdown

bigol83 commented Jan 19, 2026

Kingdom Hearts II - It needs HWZIntegerMode set to 2. If not, z-fighting strikes back.

In theory there should be no difference between mode 1 and 2 so this might be a bug. Would it be possible to have a dump showing this?

Does this include the recent zfighting fixes that are in master? If it does this breaks those, with a couple of games i tested it went back to big zfighting just like it was before zfighting recent fixes were merged.

Yes, there was a rebase error with Z floor in VK that is hopefully fixed on the last push.

Fixed in last push 👍

@Mrlinkwii Mrlinkwii added this to the Release 2.8 milestone Jan 21, 2026
@TJnotJT TJnotJT force-pushed the gs-hw-int-depth branch 4 times, most recently from a591493 to 5dbf5c3 Compare January 27, 2026 00:10
@TJnotJT TJnotJT force-pushed the gs-hw-int-depth branch 2 times, most recently from 80c7e4d to c5c21c3 Compare February 10, 2026 00:27
@TJnotJT TJnotJT force-pushed the gs-hw-int-depth branch 2 times, most recently from 4284ea0 to 3bcdc33 Compare February 19, 2026 00:03
@TJnotJT TJnotJT force-pushed the gs-hw-int-depth branch 2 times, most recently from a2bb262 to 0a9d016 Compare March 14, 2026 16:39
@TJnotJT TJnotJT force-pushed the gs-hw-int-depth branch 2 times, most recently from 57ed17b to fb4a262 Compare April 1, 2026 23:21
@TJnotJT TJnotJT force-pushed the gs-hw-int-depth branch from fb4a262 to bd5a824 Compare May 11, 2026 22:48
@TJnotJT TJnotJT force-pushed the gs-hw-int-depth branch 3 times, most recently from bbe45f3 to b55707b Compare May 16, 2026 03:23
@TJnotJT
Copy link
Copy Markdown
Contributor Author

TJnotJT commented May 16, 2026

Last push incorporates a simpler and more performant process for interpolating 32 bit integer values on the GPU, given by @TellowKrinkle.

It also adds an initial port to DX11 and GL.

Changes have not been thoroughly tested and may have bugs.

@TJnotJT TJnotJT changed the title GS/DX12/VK: Support for integer depth. GS/HW: Support for integer depth. May 16, 2026
@TJnotJT TJnotJT force-pushed the gs-hw-int-depth branch from 891e47f to 7ca579e Compare May 16, 2026 11:57
@TJnotJT TJnotJT force-pushed the gs-hw-int-depth branch from ddf30d9 to 4bfe9d5 Compare May 16, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants