gonetz / GLideN64

A new generation, open-source graphics plugin for N64 emulators.
Other
770 stars 177 forks source link

Workaround for PowerVR issues #2633

Closed fzurita closed 2 years ago

fzurita commented 2 years ago

Newer PowerVR devices need depth to be cleared every frame, otherwise most geometry is rendered behind the background.

It also needs fragment based depth to be disabled, otherwise geometry has various depth glitches.

I have not been able to figure where the driver is going wrong with either of these issues. For the 2nd issue, it almost looks like the driver is discarding fragments when they should not be discarded.

Another tidbit, if fragment based depth is enabled, then we don't have to force depth buffer clear, but at the same time, there are randomly geometry depth issues.

@gonetz What games do you think will break when we force depth buffer clear? Also, what games break without fragment based depth? I know that Pilotwings and RE2 are two of them.

See this issue for an idea of the glitches: https://github.com/gonetz/GLideN64/issues/2108

I'm fixing them now because I was given an affected piece of hardware.

fzurita commented 2 years ago

If I put a glFinish right after this line: https://github.com/gonetz/GLideN64/blob/8343fd05c9a01ce2d73f7e32bb8355036759a05b/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp#L213

It fixes the first issue at a 30% performance loss. Given that a glFinish fixes the issue, it tells me that it's most likely a driver bug.

fzurita commented 2 years ago

A glFlush also seems to fix it and the performance penalty is not nearly as bad.

Edit: Nevermind, glFlush is not working reliably enough. I kept the glFlush in the threaded opengl code just in case it's useful in the future though..

fzurita commented 2 years ago

From a lot of debugging, I have been able to find that newer PowerVR devices have problems reliably reading from gl_FragCoord.z. It almost seems like the shader does not have the latest depth data in the framebuffer set by GraphicsDrawer::_updateStates.