hrydgard / ppsspp

A PSP emulator for Android, Windows, Mac and Linux, written in C++. Want to contribute? Join us on Discord at https://discord.gg/5NJB6dD or just send pull requests / issues. For discussion use the forums at forums.ppsspp.org.
https://www.ppsspp.org
Other
11.25k stars 2.17k forks source link

[crashing] iOS jit behavior on KingdomHearts: birth by sleep #15486

Open Spidy123222 opened 2 years ago

Spidy123222 commented 2 years ago

Game or games this happens in

ULUS10505 v1.00

What area of the game / PPSSPP

Beginning of the game on the beach cutscene. It also happens when you change to interpiter and continue in game then turn jit back on then it would crash a few seconds after. Changing the graphics backend makes zero difference.

https://user-images.githubusercontent.com/64176728/163731699-185f0c35-4572-4761-814c-73a39a6c92f3.MOV

I am on iOS 15.4.1 no jailbreak (none exists either rn) and activating a debugger using libimobiledevice to allow jit to run. The crashing doesn’t happen in any other game so it’s game specific.

What should happen

It shouldn’t crash the app at all on any part of the game.

Logs

Had to convert ips to txt how it’s appropriate. PPSSPP-2022-04-17-133224.txt

Platform

iOS

Mobile phone model or graphics card

iPhone 8 Plus 64gb

PPSSPP version affected

V1.12.3-1024-g477b1773c

Last working version

Couldn’t find one

Graphics backend (3D API)

Vulkan

Checklist

Spidy123222 commented 1 year ago

Has there been any advancements on this issue?

unknownbrackets commented 1 year ago

Unfortunately, iOS isn't a well supported platform due to Apple's policies. The jit runs fine on Android devices using jit.

You can try going into Settings -> Tools -> Developer tools -> JIT debug tools, and try to find if disabling things here helps. This turns off parts of the jit so may help narrow things down.

-[Unknown]

Spidy123222 commented 1 year ago

Unfortunately, iOS isn't a well supported platform due to Apple's policies. The jit runs fine on Android devices using jit.

You can try going into Settings -> Tools -> Developer tools -> JIT debug tools, and try to find if disabling things here helps. This turns off parts of the jit so may help narrow things down.

-[Unknown]

@unknownbrackets Okay so I took your advice. I didn't get notified of your reply so sorry for delayed response but looking into crash log I saw a lot of stuff about shared memory like maybe it's a cache or virtual addressing space issue (which doesn't surprise me if it's virtual memory as some emulators have some issues with fastmem like dolphiniOS). So I turned off cached pointers and it immediately worked. I hope this info is helpful enough to help.

unknownbrackets commented 1 year ago

Interesting - that's helpful. If you turn that back on but turn off "Pointerify", does that also make it work?

Pointerify should normally be automatically disabled on iOS (and is used by cache pointers), but maybe something is wrong with it's auto-disabling.

-[Unknown]

Spidy123222 commented 1 year ago

Interesting - that's helpful. If you turn that back on but turn off "Pointerify", does that also make it work?

Pointerify should normally be automatically disabled on iOS (and is used by cache pointers), but maybe something is wrong with it's auto-disabling.

-[Unknown]

@unknownbrackets Didn't get notified for this so sorry for that but here is all of my findings we discussed in discord since it was easier to contact there.

Doing pointify doesn’t change anything still crashes. Infact it enabled made it crash earlier.

To test my memory issue theory is I turned off fast memory (fastmem) and left cached pointers enabled (unchecked no modifications). It started working like if I disabled cached pointers from before. So this is definitely memory related from what I see from testing. Idk if it’s because I am using a iPhone 8 Plus which has 3gb of ram and that a iPhone with 4gb of ram will be better suited since it can access more address space.

I would need someone else to test that with a newer device that has 4gb of ram or more with kingdom hearts birth by sleep with jit enabled (can be done using a debugger session which can be done with AltStore,sidestore,jitterbug,jitstreamer).

Sample is in first cutscene in destiny islands like the video shows in OG post. It crashes when it loads next scene in sequence when holding ventus where has loading icon on bottom right and it crashes for mine without any modification.

What gave away maybe it's a virtual addressing issue is other high bandwidth apps like dolphiniOS had this issue with fastmem. DolphiniOS in this case does use 8gb of addressing without modification which iOS devices refuse unless entitlement is given to extend it. They have a method of cutting addressing space in half to 4gb (called hacky fastmem for them) which doesn’t have problems on 4gb ram idevices which Can access I belive 4-5gb addressing space that don’t have paid dev accounts.

Once a person has a paid dev they can use entitlement extended virtual addressing which I belive extends to 10gb of space to use normal fastmem in dolphin sake here from what I'm told from Oatmealdome. Maybe when iOS gets official sideloading there shouldn't be a issue getting such entitlements for every user. I don't have a paid developer account so I can't test if extending virtual addressing helps. I'll have to get back to you people on that part as I'll likely join sidestore org which would give me paid dev features which will help test this later on once things are ironed out for our AltStore replacement.

Halo-Michael commented 1 year ago

Force the IR interpreter to be used first is 100% not currect: https://github.com/hrydgard/ppsspp/commit/b3612de528eaaf933b3884c83f609f636dbd58f8 It is true that JIT needs a lot of memory and many iOS devices have less memory than most Android device. But the best way is looking for an elegant solution when running out of memory but not that.

Spidy123222 commented 1 year ago

I'm not sure what you mean by forcing the ir interpiter. I don't think I've mentioned anything like that. What I mentioned is that disabling cached pointers helped the problem. I might be misunderstanding though.

Halo-Michael commented 1 year ago

I'm not sure what you mean by forcing the ir interpiter. I don't think I've mentioned anything like that. What I mentioned is that disabling cached pointers helped the problem. I might be misunderstanding though.

That means the newest commit force use IR interpreter on iOS, just it.

Spidy123222 commented 1 year ago

I'm not sure what you mean by forcing the ir interpiter. I don't think I've mentioned anything like that. What I mentioned is that disabling cached pointers helped the problem. I might be misunderstanding though.

That means the newest commit force use IR interpreter on iOS, just it.

Ah yeah that's not really the best approach to solve the issue as jit works fine but just on devices on lower ram suffer on it with cached pointers enabled (3gb ram devices. 2gb might not be able to do jit idk.) on it. Found that iOS devices with 4gb of ram and more do not have this issue. Knowing that, I think enabling extended virtual addressing for me would solve it if I had a paid dev account. Forcing it is definitely a downgrade for users that don't have this problem. Also cached version of interpiter works perfectly fine.

Might be best approach to comment in the pr or something also. https://github.com/hrydgard/ppsspp/pull/16925

Halo-Michael commented 1 year ago

I'm not sure what you mean by forcing the ir interpiter. I don't think I've mentioned anything like that. What I mentioned is that disabling cached pointers helped the problem. I might be misunderstanding though.

That means the newest commit force use IR interpreter on iOS, just it.

Ah yeah that's not really the best approach to solve the issue as jit works fine but just on devices on lower ram suffer on it with cached pointers enabled on it. Found that iOS devices with 4gb of ram and more do not have this issue. Knowing that, I think enabling extended virtual addressing for me would solve it if I had a paid dev account. Forcing it is definitely a downgrade for users that don't have this problem. Also cached version of interpiter works perfectly fine.

Oh sorry forgot that, it's a bug and fixed in https://github.com/hrydgard/ppsspp/pull/17026

lonkelle commented 1 year ago

I believe that just sets IR Interpreter by default on iOS but it can be changed to use JIT for devices that support it, correct?

Spidy123222 commented 1 year ago

Interesting - that's helpful. If you turn that back on but turn off "Pointerify", does that also make it work?

Pointerify should normally be automatically disabled on iOS (and is used by cache pointers), but maybe something is wrong with it's auto-disabling.

-[Unknown]

I did some testing recently. Been busy with the sidestore project for Sideloading. Managed to get a org account and see if it's a virtual memory issue and it is. I added extended virtual addressing and it fixed the issue there. so it definitely ram limits. So it's a limit on 3gb of ram iDevice and below. which means my prediction is correct. Obviously the jit can run on the 8 plus device just it might not work as well with such entitlement as devices with 4gb of ram that don't need it. image

Example of it working in later game as it also would do that before if jit was enabled and runs perfectly fine in cutscene. Cached pointers disabled which is what app came with by default on latest for me.

https://github.com/hrydgard/ppsspp/assets/64176728/b45b6246-b7eb-4349-806a-b871a6dfaa59