RPCS3 / rpcs3

PlayStation 3 emulator and debugger
https://rpcs3.net/
GNU General Public License v2.0
15.66k stars 1.93k forks source link

Metal Gear Solid 4 24fps issue #6514

Open Xcedf opened 5 years ago

Xcedf commented 5 years ago

It is well known issue, was able to bypass it with using libaudio.sprx here's the video, normally i have 24fps stuck at this stage always https://youtu.be/ximnrNKHC24 But with libaudio.sprx, video rendering is broken, menu broken as well have to blindly press Start and X to boot from save, and what most improtant as it shown in the end of the video it doesn't goes well with cutscenes and i can't progress further. I bet on SPU problem, seen same thing before in Mass Effect 2&3, and some other game even before that, than it was fixed by some spu changes from Nekotekina. If any other information is required, please let me konw.

Xcedf commented 5 years ago

Not sure if this helps, but i've decided to investigte old issues with games that needed libaudio.sprx before: Mass Effect 2 Demo, it's previous behavior look mostly close like mgs 24fps hang, was fixed by rsx commit 4a9421e2 Ninja Gaiden Sigma 1 was fixed by https://github.com/RPCS3/rpcs3/pull/4103

Snakegodeater commented 5 years ago

Any update on this issue ? Is the team Investigating this ?

dio-gh commented 5 years ago

Not at the moment as far as I know, but it'll surely be investigated eventually.

rajkosto commented 5 years ago

It is probably something audio related. I added a hack to force-lock the mutex the MGS4 MAIN PPU thread (the Audio_Port thread also locks that same mutex at that same time) usually hangs on after like 100ms of waiting, and the game continues with no audio. However it's a hollow victory because the game will softlock at the next blackscreen/fadeout. In fact, the only reason doing LLE on libaudio "fixes" the game hangs is because then the "Audio_Port" thread is stuck on sys_event_queue_receive because libaudio cannot be properly LLE'd as there's too many missing internal implementation details. "Audio_Port" thread stuck == no way for it to deadlock MGS4 MAIN thread... so the game keeps working until you hit a fadeout/cutscene loading trigger black screen, at which point you softlock similar to my hack.

If you want you can try out that hacked build from here: https://github.com/rajkosto/rpcs3/releases

Xcedf commented 5 years ago

Tried your hack in Metal Gear scene, yes it works with audio for a little while, than it encounters 24fps, issue audio fails, console shows some new lines from your hack, and game continues without audio if it was running with libaudio

elad335 commented 5 years ago

Can you upload a log for first glance?

rajkosto commented 5 years ago

Either the game PPE program on the Audio_Port thread has a code path that forgets to unlock the mutex that MGS4 MAIN thread eventually waits for, and just that code path was never hit on console because all the audio processing went on perfectly with no stalls like we have in rpcs3, or some libaudio HLE feature is missing that causes it to forget to unlock that mutex. Either way the hack leaves the Audio_Port thread in an inconsistent state so there's no further audio output, and all cinematics will just softlock afterwards.

Xcedf commented 5 years ago

Here's the lines after 24fps on rajkosto's hack E {PPU[0x1000015] Thread (Audio_Port) [0x00a554ec]} sys_lwmutex: HACK _sys_lwmutex_lock(lwmutex_id=0x95016c00) in thread PPU[0x1000015] Thread (Audio_Port) returning CELL_OK because 250000 us has passed E {PPU[0x1000001] Thread (MGS4 MAIN) [0x00a554ec]} sys_lwmutex: HACK _sys_lwmutex_lock(lwmutex_id=0x95017400) in thread PPU[0x1000001] Thread (MGS4 MAIN) returning CELL_OK because 250000 us has passed E {PPU[0x1000001] Thread (MGS4 MAIN) [0x00a554ec]} sys_lwmutex: HACK _sys_lwmutex_lock(lwmutex_id=0x95017200) in thread PPU[0x1000001] Thread (MGS4 MAIN) returning CELL_OK because 250000 us has passed E {PPU[0x1000001] Thread (MGS4 MAIN) [0x00a554ec]} sys_lwmutex: waiting thread id 0x1000017 name: PPU[0x1000017] Thread (Acoust_Thread) And here's the whole log RPCS3.log.gz Btw, i noticed that in Metal Gear level 24 fps issue happens always, but for example there is a level, bike ride with Eva, noramally it has a lots of places when 24 happens, but with this hack it runs pretty stable with audio, look's like hack's timeout or whatever is ehough for it.

Snakegodeater commented 5 years ago

So it's not CPU Related.Like many said. I had thoughts that it was Audio related too !! and it seems So. Sorry i don't know much about programming . But i can test . I'll test your built and i'll Report my system is 4790k +R9 380

Snakegodeater commented 5 years ago

Update !!! Tried your build with the demo version the game Hangs when trying to compile shaders Restarting RPCS3 Sometimes the log spams this :MEM ACCESS Violation Error Or sth !

rajkosto commented 5 years ago

Here's a funny way you actually can play through the game without audio hangs (the GPU index array type unknown and access violation crashes can still occur):

  1. Load up into gameplay
  2. Open the debugger, find the Audio_Port thread, and click Pause
  3. Once youre in a black screen which means a cutscene needs to play, click Run on the Audio_Port thread in debugger, this will make it go.
  4. After youre out of the cutscene, pause the Audio_Port thread again.

As long as the Audio_Port thread is paused, the audio based hangs cant happen. But cutscene timing is completely reliant on Audio_Port thread running, so you will need to unpause it for those to progress.

Pausing any other audio related thread like Audio_Control or Acoust_Thread will actually pause the gameplay, only Audio_Port keeps the gameplay going but without sound output.

Some sort of triple mutex threat that relies on all Audio threads and MGS4 MAIN thread locking/unlocking that mutex is causing this deadlock somehow. Or maybe more simple, the only thread that is outputting Audio to RPCS3 is Audio_Port, and RPCS3 audio implementation is buggy/lacking in some way and ends up confusing it and deadlocking the whole thing.

Xcedf commented 5 years ago

@rajkosto thanks for the info, with this i now actually manged to finish chapter 4, and now after almost a month delay, going to see if i can actually beat this game. The battle of Metal Gears and cuscenes are pretty stable itself with audio, i never seen 24fps in a cutscenes, cutscenes could crash with a Vulkan Driver error especially if you have higher IR. 1 2

rajkosto commented 5 years ago

here's some more info about the deadlock (BLUS30109 2.0):

PPU[0x10000001] MGS4 MAIN Current function: sys_lwmutex_lock
Last Mutex Wanted: 0x85016a00 (held by id: 0x1000016 b: 1)
Last Mutex Acquired: 0x85016c00 @(0x264ec8)

PPU[0x10000015] Audio_Port Current function: sys_lwmutex_lock
Last Mutex Wanted: 0x85016400 (held by id: 0x1000016 b: 1)
Last Mutex Acquired: 0x0

PPU[0x10000017] Acoust_Thread Current function: sys_lwmutex_lock
Last Mutex Wanted: 0x85016c00 (held by id: 0x1000001 b: 1)
Last Mutex Acquired: 0x0

PPU[0x1000016] Audio_Control Last function: sys_timer_usleep
Last Mutex Wanted: 0x0
Last Mutex Acquired: 0x85016400 @(0x2631fc)
PC @ 0x21f6a4

Audio_Control seems to be holding a long lived lock while it's submitting some jobs to cellSpursUrgent, which the other 2 audio threads also want to lock, and MGS4 MAIN and Acoust_Thread can sometimes swap placed in which one holds the lock and which one waits, but its usually the same every time.

The deadlock, hang, crash, whatever result is always when cellSpursAddUrgentCommand in that Audio_Control function reports 0x80410a0a, in which case it goes into a usleep(160) loop, never to escape from it. If you patch it so it does forcefully escape from it, it just breaks audio and next thing that requires audio timing will access violate. Changing the usleep period or just making that a nop so its a busy wait doesnt help either. Also its not like the UrgentCellSpursKernel0 thread gets overwhelmed with work that it can never escape from since once the Audio_Control thread gets into that usleep loop, the Urgent SPURS thread is just waiting...

Snakegodeater commented 5 years ago

@rajkosto I tried your latest build with Patch.yml and custom config file . I don't get ingame yet i stuck @ loading when press start . also i edited your patch.yml and put BLES0024 cuz i have the EU version also added the [NPEB90116] the demo version on the same YML . did i do sth wrong ? Update: i think i figured it out i need to find the game's PPU hash or sth and paste it to .yml Update 2 : Nothing works when i press new game in the demo or the normal i get the 24 fps freeze :/

rajkosto commented 5 years ago

The game should now be completable without any special trickery on good skylake+ cpu (other than LLVM out of memory error, for which clear PPU cache and load your last save then skip cutscenes) with https://github.com/rajkosto/rpcs3/releases/latest with some audio sample drops in heavy gameplay areas (better than a hang at least).

Snakegodeater commented 5 years ago

@rajkosto Thank you for the latest build . ! I tried the demo version and i can progress in-game with audio issues !!! Hope the team Fixes those Audio issues in the near future !!! 4790k+R9 380. Enabled max spurs Thread to 3 and disabled zcull queries at settings everything else on default. Use Vulkan too. Update: After some gameplay i get this : F {RSX [0x000dfa0]} RSX: class std::runtime_error thrown: Assertion Failed! Vulkan API call failed with unrecoverable error: Device lost (Driver crashed with unspecified error or stopped responding and recovered) (VK_ERROR_DEVICE_LOST) (in file C:\Projects\rpcs3\rpcs3\Emu\RSX\VK\VKHelpers.h:1101) and on the normal game i get VK_out of memory error. Buggy AMD shitty drivers for sure !

rajkosto commented 5 years ago

Some cutscenes will have lots of smoke/particle effects that will make the texture cache fill up your VRAM, doesn't happen at lower resolution scales (depends on how much VRAM you have) especially not at 100%, completely unrelated to this issue.

Snakegodeater commented 5 years ago

@rajkosto 2 GB won't stand i think But i see low Vram usage i will check again the Vram usage just to be sure. It must be a memory leak or sth. Anyway i am about to upgrade my gpu to a 1660. I am sure RPCS3 will run a lil better then.

Xcedf commented 5 years ago

@rajkosto man, this is just awesome, applied your Spurs implementations to my build, completed Metal Gear escape levele with audio and no hangs, same in Shadow Moses when you face a lots of rolling three armed things it had 24 fps, now works just fine, i'm no expert, but this a PR worthy.

Snakegodeater commented 5 years ago

@Xcedf Can you progress to act 5 ? @rajkosto how many Spurs on i7 4790k ? i'll try with 3 and unlimited and i'll report back The game maximizes the VRAM and Vram cache so i get a VK error crash at some scenes . That's a load of Vram out of there. Consider PS3 specs are a lot lower than today's Pc's specs .It must be a memory leak or sth. Or the game like KD-11 said Collects Garbages on Memory and uses it later .

Xcedf commented 5 years ago

@Snakegodeater already did it.

Snakegodeater commented 5 years ago

I get crashes Vk_out of memory . in the cutscene where snake meets the mk II and takes the solid Eye and is about to change to night vision always at the same spot.Is there any way to prevent it ? Vram usage goes to 2300 mb or sth and shared Vram too. Tried on Debug tab some settings with no luck. Also 100% resolution scale

Xcedf commented 5 years ago

@Snakegodeater it's a different issue i'm affraid, i have same crashes with IR greater than 100% a little bit after, when you returning to the street, there is an intense bombing a lots of explosion and smoke effects, it works mostly fine on 100 IR for me, but it's better to get past this area as quick as possible.

Snakegodeater commented 5 years ago

@Snakegodeater it's a different issue i'm affraid, i have same crashes with IR greater than 100% a little bit after, when you returning to the street, there is an intense bombing a lots of explosion and smoke effects, it works mostly fine on 100 IR for me, but it's better to get past this area as quick as possible.

So It's not an AMD Issue Happens on Nvidia too !!!

Xcedf commented 5 years ago

Yea, it happens on Nvidia too. Anyway with these new fixes i have finally completed this game https://www.youtube.com/watch?v=kWawgYjoZkk

Snakegodeater commented 5 years ago

Yea, it happens on Nvidia too. Anyway with these new fixes i have finally completed this game https://www.youtube.com/watch?v=kWawgYjoZkk

Heres the funny thing ! I tested your custom config file but with IR 100% and i get no glitchy sound. However i get Glitchy snake textures are missing on his body and animations are going boom. and i can't open lockers. LOL. When i delete your custom config file. I have Glitchy sound but Graphic's and phisics are fixed. That is strange !!!

rajkosto commented 5 years ago

It's not recommended to disable approximate xfloat for this game like he did, many gameplay features will break. The config options you might want to change from defaults are in the release details of my build. Don't just use other people's configs blindly.

Snakegodeater commented 5 years ago

@kd-11 must investigate the VK driver crashes then. The game is so close to playable. Same thing is happenning when using OGL too . From what i could understand it is a memory leak or sth . It seems that a lot of textures fills up the Card's VRAM . And then The driver Crashes because it seems it can't handle.

Snakegodeater commented 5 years ago

All good with Rajkosto's latest commit But if you have a weak CPU like me 4790k you get the audio hangs. Also i got MEM access Violation error FPS 20-30s . This game Is really CPU hog . Or The spu recompiler needs optimisations.Not everyone has 9900k or 8700k :/ Wonder how it runs on Ryzen Cpu's

Snakegodeater commented 5 years ago

Disabling Approximate xfloat Fixes the audio Issues for me But breaks the game's Physics Etc.

Xcedf commented 5 years ago

@Snakegodeater it not fixes it, it's just make game fast enough for audio not to hang, my build, it uses not entire Approximate xfloat instruction set, but only the minimum required, you can have the build and settings here. https://mega.nz/#!yN4EmQZC!4doE5n88x1jgyxJ9UHIwKKGRHKuQRLknmcu0baPS0S8 The settings inside for NPUB31633, rename the settings file if you want to use it for a different version of the game, and do not use my settings with another builds or enable Approximate xfloat first.

Snakegodeater commented 5 years ago

will try and report ! Does your build has the latest VK error fixes ? Your build does'nt have the latest Fixes. Like rajkosto's i just tried and VK memory error

Xcedf commented 5 years ago

@Snakegodeater i included PPU LLVM fix, VK Out of VRAM fix, and mimmap fix for icons and flat texture objects

Snakegodeater commented 5 years ago

Send me the right one. I got VK memory error

Xcedf commented 5 years ago

What do you mean the right one? I said i've included VK out of memory fix it helped me to play this game at higher resolutions, and what is your GPU btw?

Snakegodeater commented 5 years ago

Radeon R9 380 , With your settings i don't get the error at rajkosto's builds F {RSX [0x0001934]} RSX: class std::runtime_error thrown: Assertion Failed! Vulkan API call failed with unrecoverable error: Device lost (Driver crashed with unspecified error or stopped responding and recovered) (VK_ERROR_DEVICE_LOST

Snakegodeater commented 5 years ago

If you can compile a build with VK Error fixes and The MGS1 part fixes then i'll try it and report back

Xcedf commented 5 years ago

That's because i have Approximate xfloat off, and on rajkosto's builds it has to be ON, otherwise you'll keep having broken physycs and missing body parts, and this error never had anything like in MGS4, had Vulkan out of memory before this message is different.

Snakegodeater commented 5 years ago

Yeah i tried rajkosto's build with Approximate Xfloat off and i get the missing body parts etc but no VK error crashes

Xcedf commented 5 years ago

Perhaps i understand now what missing in my build, but i have no access to my VS2019 for now, so my build misses quite a big part of recent master code, i noticed that a some time ago kd-11 made some specific stability fixes, perhaps they are also include the fix for VK crash problem you have. So that's the reason it works on rajkosto's build and doesn't work on mine. Not sure that i'm going to restore my VS2019 soon, use rajkosto's builds.

rajkosto commented 5 years ago

You can now just set xfloat accuracy to "Loose" in per game config GUI on my latest build from https://github.com/rajkosto/rpcs3/releases if you want this behaviour but could you please stop spamming up this issue @Snakegodeater , these arent support forums, especially since your problem is just CPU not being good enough to keep up (or running out of video memory, which had a separate PR which is already merged in master), not the actual 24fps audio freeze issue.

Xcedf commented 5 years ago

@rajkosto, thanks for the new release, will save me a hell of a time while testing, yet i think too many instruction options now, from my long observations from different games with xfloat there're only: FCGT, FM, FS, FMA, FNMS, that make any difference in the games accuracy, the other instructions are fine being inaccurate. As for MGS4 it works fine with Approximate FM, FMA and FNMS (must be on for almost every game), other can stay inaccurate.

Snakegodeater commented 5 years ago

@rajkosto, thanks for the new release, will save me a hell of a time while testing, yet i think too many instruction options now, from my long observations from different games with xfloat there're only: FCGT, FM, FS, FMA, FNMS, that make any difference in the games accuracy, the other instructions are fine being inaccurate. As for MGS4 it works fine with Approximate FM, FMA and FNMS (must be on for almost every game), other can stay inaccurate.

Tried Approximate FM , FMA FNMS . And Xfloat Loose the game runs fine for me now with some minor bugs . But better than Before.

Xcedf commented 5 years ago

Told ya, the game just wanted a little bit more speed.

Snakegodeater commented 5 years ago

Told ya, the game just wanted a little bit more speed.

Are you going to compile a build too ?? Btw let's hope for master fixes then.

Xcedf commented 5 years ago

I've added new shadow fix to my build, but it's still misses the stuff i told you about before

Snakegodeater commented 5 years ago

For me setting FM acuracy to Default and changing Xfloat to loose game is working good .20 -35 fps. Cutscenes pretty good reaching 60s no audio issues. Enabling FM acuracy and Xfloat approximate breaks things

Xcedf commented 5 years ago

Yea, it will be faster but you'll face some problems especiaaly while aiming/shoting in first person mode.

Snakegodeater commented 5 years ago

I get this on the latest Master although F {PPU[0x1000001] Thread (MGS4 MAIN) [0x00d1826c]} class std::runtime_error thrown: Null function And then black screen. The game boots by setting PPU to interpreter . It's adviced to use the Rajkosto's builds since we don't have those Fixes on master yet. It's plauged by the black shadow bug and the 24 fps .

Snakegodeater commented 5 years ago

is this PR related to MGS4 ??? https://github.com/RPCS3/rpcs3/pull/6862