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

PPU LLVM/RawSPU: Implement MMIO violation elimination pass #14137

Merged
merged 1 commit into from
Jul 6, 2023

Conversation

elad335
Copy link
Contributor

@elad335 elad335 commented Jul 5, 2023

Implement detection of RawSPU MMIO usage in PPU code and eliminate the need to handle it in access violation handler which is a performance expensive procedure.

Massively improves performance for RawSPU games when launched with a debugger such as visual studio (because it eats the exception). going from sub-2 fps to 36 fps on Plants vs Zombies on my machine when visual studio is attached.
When a debugger is not attached, performance gains are smaller.

For the optimization to apply, you need to have a game that creates RawSPU and remove PPU cache before you do.
Some like Crysis create 5 RawSPU threads but some only 1 so some games may be more affected than others.

Here is a list of RawSPU games if you want to test.
sys_raw_spu_create.txt

@elad335 elad335 force-pushed the mmio-llvm branch 3 times, most recently from 5fd0861 to f1348e8 Compare July 5, 2023 14:40
@elad335 elad335 marked this pull request as draft July 5, 2023 17:20
@elad335
Copy link
Contributor Author

elad335 commented Jul 5, 2023

WIP because I want to add more MMIO patterns.

@elad335 elad335 marked this pull request as ready for review July 5, 2023 18:17
@elad335
Copy link
Contributor Author

elad335 commented Jul 5, 2023

Added patterns seen in Crysis, if you have already tested this pull request you may need to remove PPU cache again before retesting.

@elad335 elad335 force-pushed the mmio-llvm branch 2 times, most recently from e4dfc21 to 4004ea4 Compare July 5, 2023 18:38
for (u32 inst : insts)
{
// Common around MMIO (orders IO)
if (inst == ppu_instructions::EIEIO())
Copy link
Contributor

Choose a reason for hiding this comment

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

Old MacDonald Had A Farm... 😆

@elad335 elad335 force-pushed the mmio-llvm branch 2 times, most recently from 2eee272 to a5050fc Compare July 6, 2023 13:26
@elad335
Copy link
Contributor Author

elad335 commented Jul 6, 2023

Eliminated MMIO violations in Crysis completely while making false positives extremely rare. (this includes in fw as well, as well as in sys_raw_spu functions in liblv2.sprx)
Added a log messages:

LLVM: Detected potential MMIO32 write at [address]
LLVM: Detected potential MMIO32 read at [address]

For detected optmizations.

@elad335 elad335 requested a review from kd-11 July 6, 2023 13:31
@@ -2527,6 +2590,7 @@ void PPUTranslator::LDX(ppu_opcode_t op)

void PPUTranslator::LWZX(ppu_opcode_t op)
{
m_may_be_mmio &= (op.ra != 1u && op.ra != 13u && op.rb != 1u && op.rb != 13u);
Copy link
Member

Choose a reason for hiding this comment

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

What does register check signify here and in similar places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stack register and TLS address register are unlikely to be used in MMIO address calculation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added it as comment.

@Nekotekina Nekotekina merged commit 598fe85 into RPCS3:master Jul 6, 2023
5 checks passed
@elad335 elad335 added CPU Optimization Optimizes existing code labels Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CPU Optimization Optimizes existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants