Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rsx: Implement Z value snapping to account for precision errors #11766

Merged
merged 2 commits into from Apr 13, 2022

Conversation

kd-11
Copy link
Contributor

@kd-11 kd-11 commented Apr 11, 2022

Snap resulting Z values to integral stops to try and account for precision errors.
The cause of the errors is actually the inversion of w. Large w values will give very small results that have tiny precision loss. The computed NDC Z is then very slightly outside the range we want (e.g 1.0000001 in a Z range of 0.99-1.0)

Fixes #11669
Fixes #11765

@hvhbot
Copy link

hvhbot commented Apr 11, 2022

image
Still there

@kd-11
Copy link
Contributor Author

kd-11 commented Apr 11, 2022

Interesting. The value I picked solves the issue on amd but not nvidia. This will be messy lol.

@jonibim
Copy link

jonibim commented Apr 12, 2022

image

The issue is still present in SEGA Rally

@Linear524
Copy link

I noticed that a lot of things are renders fine on amd but have some precision issues on Nvidia...
Maybe there is some global tweak required for Nvidia driver to fix all those issues by one shot ? Like some calculation switch, something similar to denormals flushing to zero, or positive/negative... Or additional Rounding mode... Or Extra Clamping mode + preserve sign...

@hvhbot
Copy link

hvhbot commented Apr 12, 2022

Interesting. The value I picked solves the issue on amd but not nvidia. This will be messy lol.

I have amd gpu(rx 470)

@kd-11
Copy link
Contributor Author

kd-11 commented Apr 12, 2022

Interesting. The value I picked solves the issue on amd but not nvidia. This will be messy lol.

I have amd gpu(rx 470)

Odd, the issue is fixed on my 6700XT.
I'll have to just use a larger range.

@jonibim
Copy link

jonibim commented Apr 12, 2022

Still the same issue on Sega Rally :/

GPU: Nvidia Quadro P1000

@kd-11
Copy link
Contributor Author

kd-11 commented Apr 12, 2022

Extended the range, check if the new build is better once its ready.

@jonibim
Copy link

jonibim commented Apr 12, 2022

The best value that worked for me was 0.00011875. I came up with this value by doing a binary search on a range until I would find something that would give the best results 🤣. Also, any number > 0.0002 fixes the flickering problem, but presents other issues, such as the background of the game looks like it has a low render distance, so that you see the background popping in as you get closer to it. Any number < 0.00011875 reveals the broken sky problem. There probably exists even a better value between 0.0002 and 0.00011875, however at least this number does the trick for Sega Rally

BEFORE_FIX
AFTER_FIX

@kd-11
Copy link
Contributor Author

kd-11 commented Apr 12, 2022

Hmm, it may be possible to automatically calculate the range. I'll try and infer the range from the Z range.

@kd-11
Copy link
Contributor Author

kd-11 commented Apr 12, 2022

Reimplemented using an algorithm to calculate the breakpoint where changes in the Z value have no impact on the Z buffer anymore. This actually works out very close to your estimate, the real value works out to around 0.000119209296656.
This value is dynamic and depends on the scene setup so it should not unfairly corrupt geometry that does not require the fixup.
@jonibim @hvhbot Please retest

@jonibim
Copy link

jonibim commented Apr 12, 2022

It works great on Sega Rally! 👍

@Xcedf
Copy link

Xcedf commented Apr 12, 2022

Crysis 3 doing well, sky's fixed
14

@hvhbot
Copy link

hvhbot commented Apr 12, 2022

image
Issue is fixed

@kd-11 kd-11 marked this pull request as ready for review April 12, 2022 20:07
@kd-11 kd-11 changed the title [WIP][TESTERS NEEDED] rsx: Implement Z value snapping to account for precision errors [TESTERS NEEDED] rsx: Implement Z value snapping to account for precision errors Apr 12, 2022
@Jhonny-2005
Copy link

Lgtm

@thuru
Copy link

thuru commented Apr 13, 2022

@kd-11 please take a look at issue #10955 I believe you are very close to solving it but it seems it still dIsn't solve there. Thanks

@kd-11
Copy link
Contributor Author

kd-11 commented Apr 13, 2022

#10955 is a similar bug but it happens much earlier in the pipeline. It will need a slightly different fix.

@kd-11 kd-11 changed the title [TESTERS NEEDED] rsx: Implement Z value snapping to account for precision errors rsx: Implement Z value snapping to account for precision errors Apr 13, 2022
@kd-11 kd-11 merged commit 60cbd7a into RPCS3:master Apr 13, 2022
@kd-11 kd-11 deleted the sticky-z-buffer branch October 16, 2022 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants