protonscr

Something wrong with dx9 Half-Pixel Offset thing

dxvkclosed d3d9
doitsujin/dxvk#1864 · opened 2020-12-24 by pchome · updated 2020-12-25 · 3 comments · github
Ppchome 2020-12-24 github

In many DX9 games there are noticeable ~1px borders (top and bottom, left and right, or both). Usually empty and hard to observe, but in some cases they got filled with garbage which has visible contrast with nearest content. Sometimes it's just mirrored content from opposite side.

d9vk-border

This issue present there for a long time, some specific games to name:

  • I remember one of Mass Effect games, galaxy map on the bridge has "content reflections"
  • Trackmania Forever
  • Some games has very noticeable shift on intros (AMD logo, etc)
  • Sky Drift (see above screenshot)

I found this code while trying to figure out why this happens
https://github.com/doitsujin/dxvk/blob/56399e49d1cdd9728fee008590fd25be905e074d/src/d3d9/d3d9_device.cpp#L5190-L5202

By removing correction it makes this screen look ok, but "Results" screen still has "borders", also this brakes other games (obviously, Alan Wake has red left and bottom borders).

d9vk-border-v2

Also googled this descriptions
https://aras-p.info/blog/2016/04/08/solving-dx9-half-pixel-offset/
http://www.virtualdub.org/blog/pivot/entry.php?id=366

With 2D rendering, the story is different. In this case getting the mapping right is critical, and failure to do so can result in serious artifacts such as directional smearing with multiple passes. My favorite symptoms are one pixel gaps along two edges of the screen, missing corners on rectangles drawn using lines, and a 2x2 box filter blur across the entire image.

So this line likely describes what I see in those games and makes me believe there is a bug somewhere.

There are descriptions in those articles how they fixing the issue by modifying vertex shaders, maybe such solution would be better for dxvk too?

System information

  • GPU: Nvidia
  • Driver: latest
  • Wine version: 5.22 (virtual desktop)
  • DXVK version: latest

Apitrace file(s)

  • (remind me where I can just drag-n-drop ~200MB file)
KK0bin maintainer 2020-12-24 github

(remind me where I can just drag-n-drop ~200MB file)

Google Drive or Mega for example

There are descriptions in those articles how they fixing the issue by modifying vertex shaders, maybe such solution would be better for dxvk too?

To quote the article:

Unfortunately we can’t fix it by changing all coordinates passed into SetViewport, shifting them by half a pixel (D3DVIEWPORT9 coordinate members are integers).

Vulkan viewport coordinates are not integers so this is how it currently works in DXVK.

I remember one of Mass Effect games, galaxy map on the bridge has "content reflections"

What do you mean? I just tested Mass Effect and didnt notice anything about the galaxy map.

Mmisyltoad 2020-12-24 github

What happens if you use a bias of
float cf = 0.5f - (1.0f / 64.0f); ?

It could just be that you're getting unlucky and something is making your half-texel offset into a full texel offset in nearest on your HW and it needs a larger bias.

Ppchome 2020-12-25 github

@Joshua-Ashton

What happens if you use a bias of
float cf = 0.5f - (1.0f / 64.0f); ?

No visible changes.

But I checked some other games in different configurations and appeared it was reshade/vkBasalt bug. Sky Drift bug just looks similar, maybe some bad shaders or so.

FWIW, still using old vkBasalt version (0.3.0), so I'm not even sure if the bug still present in recent versions.

@K0bin

I remember one of Mass Effect games, galaxy map on the bridge has "content reflections"

What do you mean? I just tested Mass Effect and didnt notice anything about the galaxy map.

This: when on darker border you can see lighter pixels from opposite side
d9vk-border-v3
(most visible on top-right and bottom-left)
This screenshot was taken with vkBasalt enabled. No such "glitches" otherwise.

Not dxvk bug, closing.

Nothing extracted yet.