PCSX2 / pcsx2

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

[Feature Request]: Replace the EE Timing Hack with an instant DMA behaviour. #5970

Closed ghost closed 1 year ago

ghost commented 2 years ago

Description

From the informations I got when reading the PCSX2 code, we have a "EE Timing Hack" which is designed to work around the various timing issues we could encounter in various games when ran into PCSX2.

However, this hack have nothing to do with the EE funny enough if I am correct, it mostly impact the DMAC timing model judging by the code.

It seems this hack was done as a general purpose solution for every components in the PS2 CPU. But, PCSX2 improved "a lot" regarding timings in several key areas (GIF and IPU for example).

I ran several tests for the games that does use this hack, or even the ones that don't need it. And the results I got from my testing are very, very interesting.

Case 1 : VU1 running too fast

Games Impacted by this :

Probably other games too.

Those games have the EE Timing hack applied, despite PCSX2 having the ability to emulate those games just fine by running the VU1 at it's correct timing (without instantVU1).

Case 2 : DMA writes when busy signal is engaged

Games Impacted by this :

Probably many, many other games too.

After reading the PS2 documentation and PCSX2 code, it seems the PS2 could issue a DMA write when busy only in certain specific scenarios, I guess hardware tests will be necessary for that.

// DMA Writes are invalid to everything except the STR on CHCR when it is busy // However this isn't completely confirmed and this might vary depending on if // using chain or normal modes, DMA's may be handled internally.

Case 3 : VU0 running too fast

Games Impacted by this :

Well, the solution to this is pretty simple, replacing the timing hack with the VUsync hack.

Reason

There is a huge missed oportunity here. Speed.

A general timing hack doesn't seem necessary anymore at the current state of the emulator, and we misses an opportunity which can makes PCSX2 faster in many games, noticeably, Ratchet and Clank.

The BIOS (thanks to Sony's horrendous code) has an "instant DMA" hack applied at runtime, which allows to get around the need to the EE's Dcache.

However, making DMA's instant for a general pupose would have 3 benefits:

An example of this would be Myst 3, currently, the game have a patch and the timing hack together in order to get around an evil race condition in the game.

With an "Instant DMA" option, the patch could be removed, and just the "Instant DMA" hack would be sufficiant.

This could also makes the DMA busy hack completely irrelevant, as the instant nature of such an option would eliminate this kind of problem.

As a bonus, this gets around the need of the EE Dcache in many cases.

Ratchet and Clank for example, really takes advantage of an instant DMA, the game runs approximately, 5% faster with it.

5% is minor yes, but it adds up. And some games can see even more of a boost, Chicken Little can go up to 10%!

If the DMA is instant, I assume putting it on an other thread, while very hard I would imagine, would not be impossible, and the speed gained by this, would be imense.

Examples

There isn't really an example applied elsewhere unfortunately.

refractionpcsx2 commented 2 years ago

The Instant DMA stuff would need more work than it currently does in the BIOS hack (which doesn't work for general purpose) as VIF and GIF for example can wait on other things happening on different units, so it will need to be able to break out of the loop, which the current way it cannot.

But yes, it would be better, potentially, though we might need both, in cases where PATH3 masking games require the EE Timing hack, there still needs to be a sense of timing between VIF and GIF, rather than either one ending "instantly".

coornio commented 2 years ago

Inbefore this gets the Texture Preloading -like treatment with a None/Partial/Instant dropdown.

waspennator commented 2 years ago

Looks like a recent pull added in the instant dma hack stuff.

refractionpcsx2 commented 1 year ago

I'm not removing the EE timing hack as it still has utility in some cases (path3 masking is more sensitive to instant)