PCSX2 / pcsx2

PCSX2 - The Playstation 2 Emulator
https://pcsx2.net
GNU General Public License v3.0
11.65k stars 1.61k forks source link

GSdx: 2 passes alpha test isn't accurate (wrong order) #1499

Open gregory38 opened 8 years ago

gregory38 commented 8 years ago

Game: Kengo Letters rendering is awful, seem to miss pixels (first screen if you have no memcard save)

Game will render 2 sprites by letters with Alpha Test enabled (RGBA only, i.e. depth will be discarded if alpha failed the test). Both blending and depth test are enabled too. (note: on this particular case, depth test is useless)

Current algorithm does:

  1. render all pixels that pass alpha test (color + depth)
  2. render all pixels that fail alpha test (only color)

The 2 passes doesn't conserve the order of primitive for blending operation. First primitive could be discarded because it failed the alpha test. And it will only be executed in FS in the 2nd phase of the algorithm.

The game uses a constant MAX depth for primitives in GREATER_OR_EQUAL mode. So in this case, we don't need to guarantee the order of the depth buffer (equivalent to ALWAYS). And it would be a solution to compute first color (of all fragments), and then the depth (of fragment that pass the alpha test). However it would be nice to find a generic solution, if possible, as HW is quite limited here.

FlatOutPS2 commented 8 years ago

It's the same issue as Driv3r, Ridge Racer V, and Burnout games text.

gregory38 commented 8 years ago

Look similar or proven to be the same? It might worth to check the depth value of the primitive. In kengo depth test will never failed (due to the usage of max value). If this property holds, I can fix it.

FlatOutPS2 commented 8 years ago

Not sure if it's exactly the same, but they're text issues caused by an inaccurate alpha test.

I'm not 100% about Driv3r, but when I recently hacked a fix for the Burnout games, it slightly improved Driv3r as well. EDIT: The same hack also fixes Kengo(it causes regressions in other games though, because I was just stabbing in the dark). :p

gregory38 commented 8 years ago

could you give me a gs dump of burnout letter so I can quickly compare the alpha testing.

FlatOutPS2 commented 8 years ago

There's one in the issue about it: https://github.com/PCSX2/pcsx2/issues/935

gregory38 commented 8 years ago

Thanks you. Yes it is the same issue. And they also use 0xFF_FFFF (aka the max) as depth value. It is strange because depth buffer already contains the max value. So as Kengo, Alpha test is useless. Or maybe I failed to see the real effect due to depth rounding. (or likely game designer were high again...)

FlatOutPS2 commented 8 years ago

Did you look at Ridge Racer V as well? It's not exactly the same as Kengo and Burnout, but it might be insightful.

escape209 commented 8 years ago

I found that using Relaxed Depth in ZeroGS actually fixes the text (for the most part) in Burnout Revenge. zerogs

FlatOutPS2 commented 8 years ago

And you prefer that to this: :p

revenge

escape209 commented 8 years ago

@FlatOutPS2 is that on ZeroGS as well? How did you get the text to look so clean?

FlatOutPS2 commented 8 years ago

No, that's using a custom build of a recent GSdx.

escape209 commented 8 years ago

@FlatOutPS2 Could you link me a copy of your custom build? Just for curiosity purposes.

gregory38 commented 8 years ago

this branch ought to improve text rendering (I will do a pr later) https://github.com/PCSX2/pcsx2/tree/gsdx-nouveau-driver

FlatOutPS2 commented 8 years ago

So your PR will be for OGL only? :/

gregory38 commented 8 years ago

Hum hum. You can do it for Dx too.

FlatOutPS2 commented 8 years ago

OGL and DX branches have been merged, so this can be closed as well.

gregory38 commented 8 years ago

Technically the issue is still here. It was fixed on some cases only. Let's hope it will be enough as I'm afraid we can't do better

FlatOutPS2 commented 8 years ago

Yeah, just noticed Stuntman seems to still have the issue:

Stuntman.zip

I usually don't play the game in HW mode, because it runs and looks horrible.

sudonim1 commented 8 years ago

I should have commented on this before. There is no such thing as the "correct order", both orders are hacks to partially implement what actually happens and will not work for all games.

gregory38 commented 8 years ago

My changes are 100% correct when there are enabled/valid. Otherwise it will use the old code. I won't call it a hack. However it can't be always activated, it would be too easy

gregory38 commented 8 years ago

@FlatOutPS2 The first dump is the same issue. However I can't use the same trick here. Wait maybe I can use a variation. Depth of primitives are constant and use the operation greater or equal. Which means

MrCK1 commented 8 years ago

I'll check HSG4 later if I can get TeamViewer to work. Font rendering has been broken for a while

FlatOutPS2 commented 8 years ago

I'll check HSG4 later if I can get TeamViewer to work. Font rendering has been broken for a while

The Stuntman fixing PR also fixes HSG4 text, though there's still an issue with the logo's circular outlines appearing over the text instead of behind it: Everybody's Golf.zip

There's a finger pointing towards the issue. :p

gregory38 commented 8 years ago

Sorry I can't do better for EG. It can only be done with a full SW emulation. My GPU doesn't support it so I won't do it (and I'm not sure it will be fast neither)

bositman commented 8 years ago

Just noting that this also fixed God of War letters as well :)

gregory38 commented 8 years ago

Oh very cool.

gregory38 commented 8 years ago

@FlatOutPS2 @ssakash

I got a task for you. Not sure who want to do it.

Implement this optimization in the SW renderer.

    if (m_om_dssel.ztst == ZTST_GEQUAL && m_vt.m_eq.z && v[0].XYZ.Z == max_z) {
        m_om_dssel.ztst = ZTST_ALWAYS;
    }

It is few draw call but often full screen draw call. So it could help. And potentially it could allow further optimization as there is a fast path when there is no pixel test enabled.

ssakash commented 8 years ago

@gregory38

Just for reference, do you know any games which hit the true branch of your suggested optimization? I don't seem to encounter any such cases on the games I have tested. GS dump of such cases would be nice to measure performance impact.

gregory38 commented 8 years ago

Did you try the gs dump from this thread? Check used to be bad letter rendering. GTA, burnout, GoW... I'm surprised it isn't more often. I will post you some dump tonight.

gregory38 commented 8 years ago

https://ufile.io/1af32

https://ufile.io/86634

ssakash commented 8 years ago

Thanks for the GS dump download links - unfortunately useless on my side as my 4G quota expired and I'm stuck with this 2G (GSM) which can't even handle a download of 1Mb... (FFS even a git push -f takes a ridiculous amount of time to get pushed to remote branches)

Either way, I'll try to open the PR for the Software mode optimization within tomorrow. (Performance testing of the no-pixel test fast path can be done there) FWIW the changes are ready in local branch, just trying to beautify the code before making a PR :)

FlatOutPS2 commented 8 years ago

I quickly made a very rudimentary implementation of this, and it's definitely triggered by the Burnout games, but I noticed no impact. But that might just be down to where and how I implemented it. I'll await the PR.

MrCK1 commented 7 years ago

@gregory38 Are we leaving this open for future improvements, or is it all set for the 1.6 milestone?

gregory38 commented 7 years ago

Keep it open for everybody golf. But we can remove 1.6 tag

lightningterror commented 6 years ago

Rozen Maiden Duellwalzer is also affected by the same issue.

The text isn't rendered correctly in HW renders.

SW gsdumpgui 2018-06-11 16-22-00-33

HW gsdumpgui 2018-06-11 16-23-03-67

Running debug build triggers ASSERT(m_vt.m_min.p.z > max_z); // sfex capcom logo in GSRendererDX/GL

GS dump. Rozen Maiden Duellwalzer.gs.zip