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: Restructure ZCULL handling #12020

Merged
merged 23 commits into from
May 20, 2022
Merged

rsx: Restructure ZCULL handling #12020

merged 23 commits into from
May 20, 2022

Conversation

kd-11
Copy link
Contributor

@kd-11 kd-11 commented May 16, 2022

The motivation behind this one is interesting. The reason ZCULL emulation is so slow is that NVIDIA lumped in timestamp reading with passing occlusion samples as one object called a report. So if a game is just using the reports to tell the RSX time or check on RSX progress using timestamps we cannot tell if it wants to read the timestamp or wants to know how many samples have been rendered so far. Timestamps are very cheap to calculate, but counting samples is very slow and punishing as we have to send work to the GPU and wait for the results to come back. However, while making a hacked build for debugging, I realized something - most games use a library call to read timestamps despite the fact that they can just read the values themselves! This gives us a semi-reliable way of knowing if the game just wanted to see the current timestamp allowing us to skip doing the expensive sample evaluation every time.

Changes:

  • Force cellGcmGetTimestamp to be HLE. This allows us to use super memory to read timestamp values without disturbing ZCULL behavior. Of course some games will not use this method, so we need page locking.
  • Lock active ZCULL memory. In many games, we're not even seeing faults in this region, because they aren't actually doing anything with the report data. They just wanted the timestamps, which we can check for cheaply using cellGcmGetTimestamp.
  • If a game requests for conditional rendering, try to calculate it on the GPU as much as possible. It is faster to just assume it is visible and let the GPU do the culling work instead of trying to emulate it on the CPU.
  • Work analysis in several titles showed that calling ZCULL_control::update every RSX cycle is a very poor way of doing work efficiently. Doing it every 64 loop cycles is a lot more efficient and the duration between calls is actually large enough that we get a much better hit ratio. This improves CPU efficiency by a lot.
  • Minor optimization: Get rid of std::multimap for image view tables. It is easier to just encode for what we want.

kd-11 added 18 commits May 16, 2022 20:11
- It's over 1k lines of code in its own namespace; it really should be in its own file
- If nobody is reading RSX reports, do not be in a hurry to write them
- Requires HLE of some methods (cellGcmGetTimestamp) to function correctly
- This is the only way to know if a report is being used for ZCULL or timestamps only.
  If the game is not reading the ZCULL data, the access guards will detect it and optimize usage around that.
- Pass a sync address to the backend
- Ignore the hint if the query is running in lazy mode
- Do not submit CBs too close to each other. Submits are expensive
- This has a negative impact when ZCULL is active due to spamming __rdtsc
- While the method is fast, it is not free and some checks are done before the instruction can be emitted
  Let's use the saved time to actually get something useful done
- Do not acquire eng lock while holding the page lock
  RSXThread may be waiting on the page lock and will never ack the pause request
@kd-11 kd-11 marked this pull request as draft May 16, 2022 17:27
- Reset backend interrupt in core handler
- Separate memory config interrupt from regular backend interrupt
@hvhbot
Copy link

hvhbot commented May 16, 2022

RPCS3.zip
Killzone 2 crashes with verification failed error few seconds after going ingame

@cipherxof
Copy link
Contributor

50% increase in MGS4.

Master:
master

PR:
pr


check_state(ptimer, flush_queue);

// Disabled since only ZPASS is implemented right now
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a TODO here

set_eval_result(pthr, failed);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mssing newline

@Blackbird88
Copy link

Blackbird88 commented May 16, 2022

MGS4 crashes with this error (RTX 3070)
F {RSX [0x0a11438]} SIG: Thread terminated due to fatal error: Verification failed (in file C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\rpcs3\Emu\RSX\RSXThread.cpp:1752[:3], in function get_current_vertex_program)

@00ChuChu00
Copy link

Infamous 1
Master:
Before PR

PR:
PR

@kd-11
Copy link
Contributor Author

kd-11 commented May 16, 2022

RPCS3.zip Killzone 2 crashes with verification failed error few seconds after going ingame

Confirmed, I'm investigating.

@Emogop
Copy link

Emogop commented May 16, 2022

Not much for a Insomnian games.
Resistance 2: (ZCULL Accuracy: precise)
Master (fluctuates 46-47)
Screenshot_94
PR (fluctuates 46-50)
Screenshot_95
Also Ratchet & Clank: Tools of Destruction™ (ZCULL Accuracy: approximate)
Master: 34 FPS
PR: 35 FPS
God of War 3 (ZCULL Accuracy: approximate)
No changes at all.
Persona 5 (ZCULL Accuracy: approximate)
More or less the same, even slightly worse with PR, as framerate fluctuates more (43-45 master, 41-46 PR)
Master:
Screenshot_97
PR:
Screenshot_98
God of War® Collection, GoW 1 (ZCULL Accuracy: approximate)
The first game the PR has an upper hand.
Master (ranges wildly from 132-149)
Screenshot_100
PR (ranges slightly, 160 fps +- 3 frames)
Screenshot_99

i7 6700 ES (3,7 Ghz all cores)
GTX 1060

@kd-11
Copy link
Contributor Author

kd-11 commented May 16, 2022

R&C (and infamous to some extent) have other issues related to high draw call count. I'm aware of the problems and investigating solutions.

- This is much better than polling on atomics every cycle for something that happens a few times during gameplay
@Jonathan44062
Copy link

Jonathan44062 commented May 16, 2022

Sonic Unleashed crashes with
Verification failed
(in file C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\rpcs3\Emu\RSX\RSXThread.cpp:1954[:3], in function get_current_fragment_program)
A few minutes of gameplay
RPCS3.log

Ignore what I said, the last commit fixes Sonic Unleashed, no crashes with Verification failed

@Dormant-Hero
Copy link

4 fps tests with before and after pics here https://docs.google.com/spreadsheets/d/1qKh85piJXA8JsSC_Hp8Fs2L3l9ouyhWHXWimyak1TGk/edit?usp=sharing .

Uncharted 2 seems to be now broken for me with the exact same settings which are not the most stable but at least consistent in reaching the test zone. logs attached of the 2 issues that occur on PR when I attempt to reach save point. I do not even make it past the fist loading screen properly on the PR.

Not sure if anyone else can test uncharted 2 and see if it is an issue for them. Going to retest on updated PR.

RPCS3(2).zip

RPCS3(3).zip

@Dormant-Hero
Copy link

Dormant-Hero commented May 16, 2022

Okay ignore my uncharted 2 comment. Seems to work with the latest version of the PR just posted for windows as per the below:

image

Added to my google sheet for comparison https://docs.google.com/spreadsheets/d/1qKh85piJXA8JsSC_Hp8Fs2L3l9ouyhWHXWimyak1TGk/edit?usp=sharing

@Xcedf
Copy link

Xcedf commented May 16, 2022

Got this error in GTA V
F {RSX [0x0a11438]} SIG: Thread terminated due to fatal error: Verification failed (in file C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\rpcs3\Emu\RSX\RSXThread.cpp:1752[:3], in function get_current_vertex_program)

@kd-11
Copy link
Contributor Author

kd-11 commented May 16, 2022

I know what's causing it, I'm working on fixing it without hurting performance.

- The interrupts are for multithreaded signals andmake the main loop run more aggressively for the next cycle
@kd-11
Copy link
Contributor Author

kd-11 commented May 16, 2022

A tentative fix is up for the crash. Let me know if you're still getting crashing once its done building.

@Darkhost1999
Copy link
Contributor

This appears to have fixed the crash I was experiencing when testing
Screenshot_20220516-134408.png

For the curious "does this fix GTA V disable zcull occlusion queries"
I tested on the first commit and it looked like
Screenshot_20220516-140240.png
So I suspect it's a different issue.

@Xcedf
Copy link

Xcedf commented May 16, 2022

@kd-11 tested for half an hour in gta v crash seems gone
@Darkhost1999 it is a different issue, disabling ZCull just removes the water reflection layer, which has this issue

@CatKasha
Copy link

CatKasha commented May 16, 2022

comparison with v0.0.22-13600-2ba437b6 and v0.0.22-477dc0f5
clean install, 4.89, default settings + performance overlay, 3700x stock, gtx760 (472.98)

DiRT™ Demo [NPUB90042]
same fps
loading time has increased
on both version, crash after force close when stuck on loading screen (static image), to reproduce it play first event, then open latest (ill create issue with logs later)

DiRT 2 Demo [NPUB90294] - no regression and crashes, same fps with unlocked fps

METAL GEAR SOLID 4 DEMO VERSION [NPUB90176] - tested only first area when player got control, cant tell about stability
fps has increased with unlocked fps
v0.0.22-13600-2ba437b6
main
pr v0.0.22-477dc0f5
pr

v0.0.22-13600-2ba437b6
main2
pr v0.0.22-477dc0f5
pr2

@Linear524
Copy link

@cipherxof, how did you fix MGS4 z-fighting issue on master builds ? Far ground textures is always flickering for me...
I heard that it is an attribute precision issues with Z-fighting problem.

@kd-11
Copy link
Contributor Author

kd-11 commented May 17, 2022

@cipherxof, how did you fix MGS4 z-fighting issue on master builds ? Far ground textures is always flickering for me... I heard that it is an attribute precision issues with Z-fighting problem.

They don't. Custom builds use an old hack with exaggerated polygon offset.

@hvhbot
Copy link

hvhbot commented May 17, 2022

Before:
image
After:
image

@kd-11 kd-11 marked this pull request as ready for review May 20, 2022 12:39
@kd-11 kd-11 changed the title [TESTERS NEEDED] rsx: Restructure ZCULL handling rsx: Restructure ZCULL handling May 20, 2022
@kd-11 kd-11 merged commit ec2d529 into RPCS3:master May 20, 2022
@Linear524
Copy link

All latest version keeps freezing on GoW3 and Ratchet & Clank titles...
No log errors, just sudden freeze like RSX dies silently :(
Other games runs fine (Killzone, Gran Turismo 6, Persona5, TLoU, etc...

@kd-11
Copy link
Contributor Author

kd-11 commented May 20, 2022

All latest version keeps freezing on GoW3 and Ratchet & Clank titles... No log errors, just sudden freeze like RSX dies silently :( Other games runs fine (Killzone, Gran Turismo 6, Persona5, TLoU, etc...

Please open a proper bug report ticket with appropriate logs and steps to reproduce.

@tamburro92
Copy link

tamburro92 commented Aug 10, 2022

Introduced a new bug on mac os:
#12158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.