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

"Load State Automatically" work less well than manual load state #1433

Open
schmurtzm opened this issue Sep 1, 2022 · 41 comments
Open

"Load State Automatically" work less well than manual load state #1433

schmurtzm opened this issue Sep 1, 2022 · 41 comments

Comments

@schmurtzm
Copy link

schmurtzm commented Sep 1, 2022

Hi, I know that states are not perfect in mame2003-plus as it is indicated as "game-dependent" in libretro documentation. But it seems not normal to have a very big difference of behavior between an automatic load state and a manual load state in Retroarch.

Problem description :
"Load State Automatically" work less well than manual load state

How to reproduce :
The 194x games are really a good test panel 😄 :

  • When using "Load State Automatically" in Retroarch, the save state is restored directly when the rom is loaded :

    • 1941 resume without sound (just an horrible tone)
    • 1942 resume correctly
    • 1943 resume without image : Only some entries like scores but no sprites or background (but sound OK).
  • If I disable "Load State Automatically" in retroarch, load my game and then do a manual resume, all this 3 games resume correctly.

Remark : when the state is loaded automatically and failed, you can select "restart" in retroarch and then manually load the state to make it work.

I have tested with a fresh retroarch compiled and the very last version of mame2003-plus too. I reproduce this behaviour on the Miyoo Mini (little Linux handheld console) and on PC / Windows.

The issue is probably old because I think that it is the same behavior described in this issue for mame2003 : libretro/mame2003-libretro#72

Logs
Here some verbose debug logs from auto-resume state with the 3 games: RA debug logs - auto resume state - 194x .zip

@markwkidd Seems to think that it could come from Retroarch and not from the core. Let met know if you need that I create this issue on Retroarch repo.

Thank you !

@MistyDreams
Copy link
Contributor

this is a feature I dont use, if you can give me the steps to reproduce. I can try see whats going on seems if manual works auto should surely.

@schmurtzm
Copy link
Author

schmurtzm commented Sep 1, 2022

Yes it should have the same behavior but it's not the case.

Reproduce is quite simple :

image

1 - run retroarch and go to settings -> saving and activate auto save state and load state automatically
2 - load the rom 1943 (generally I just drag and drop the rom in RA windows or use command line)
3 - quit retroarch (it will automatically generate a state called 1943.state.auto )
4 - launch retroarch and load 1943 again (do not use history menu otherwise it doesn't restore the state)
Now you see that it resumes without image : only some entries like scores but no sprites or background (but sound OK).
5 - choose the option Restart in retroarch menu and then Load state -> the previous state is now working when you do it manually.

Thank you for your support :)

@schmurtzm
Copy link
Author

PS: the -e arg allows to load a specific state. This command line triggers the same problem as load state automatically.

To use it, rename your save state like this : 1943.state1.entry and call it like this :
retroarch.exe -L "cores\mame2003_plus_libretro.dll" -e 1 "arcade_test\1943.zip"

@schmurtzm
Copy link
Author

schmurtzm commented Sep 1, 2022

To illustrate :
a failed automatic load state :
image

a manual load state (obtained with the same save state file) :
image

@MistyDreams
Copy link
Contributor

MistyDreams commented Sep 1, 2022

Might take a minute to look at this will need to check manual vs auto and if they both SERIALIZATION or the core functions. This will require looking at the RA code.

@schmurtzm
Copy link
Author

You make me dream because I know that a lot of persons are annoyed by this problem since a long time 😄

@schmurtzm
Copy link
Author

@MistyDreams
Copy link
Contributor

not really seems to get the info from the core.info file rather than the core. The code needs traced to see what its doing to see why one is failing and the other isint. Its quite bizarre this is set from a external file and not the core itself.

@MistyDreams
Copy link
Contributor

@mahoneyt944 @arcadez2003 do you guys know how ra supports savestate is it serialization or core based for both auto and manual?

@mahoneyt944
Copy link
Collaborator

mahoneyt944 commented Sep 2, 2022

Admittedly save states is something I've ignored for awhile since it's functionally is spotty in 2003+. But I believe the issue is because the machine needs to load before the state is applied or you'll get this kind of behavior. Maybe we could flag when the machine is "ready" and then allow the autostate to be applied

@schmurtzm
Copy link
Author

Admittedly save states is something I've ignored for awhile since it's functionally is spotty in 2003+. But I believe the issue is because the machine needs to load before the state is applied or you'll get this kind of behavior. Maybe we could flag when the machine is "ready" and then allow the autostate to be applied

Thanks for your investigations 😀 !
You are very probably right because I've just made a new test : load the 1943 rom and press F4 (frantically) to load manually the last state quicker as possible .... and the issue comes back again !
So yes it is definitively related to the fact that the core is loading state before having terminate to load the rom.

@barbudreadmon
Copy link
Contributor

But I believe the issue is because the machine needs to load before the state is applied or you'll get this kind of behavior. Maybe we could flag when the machine is "ready" and then allow the autostate to be applied

I believe automatic load is calling retro_unserialize before any call to retro_run has been made, you'd need to either leave retro_load after the machine is fully ready to accept savestates, or to improve savestate support to the point they will work even if the machine has yet to run a single cycle. FWIW, FBNeo is doing the later, and this is also needed for libretro features like runahead or netplay.

@MistyDreams
Copy link
Contributor

MistyDreams commented Sep 2, 2022

Ill need to look the libretro.h I dont think we have any control over that initialisation order of the order of retro_load/unload. The front end allows cores to do very little flexibility between cores and itself you would require communication to do that. @mahoneyt944 how would you flag auto_load per say for example? Some games do work with rewind funnily enough very odd will need to look through the libretro docs to see how the condition if serialisation is ready or not is sent to the front end.

For this testing im going to have to redo the mame078 fixes to compile in msys2 need to know if load states are working. There was a memory addressing in the 68k as well when I done it last time but we need a debugger in some cases to see what going on with the core like with the system16 issues for the sound not working. I do think its interrupt related though need to look back into it as the 68k was having issues think its due to 64/32 bit issues.

@MistyDreams
Copy link
Contributor

https://www.libretro.com/index.php/develop/ the step by step last link is missing from the docs suppose ill need to look at the ra source to figure this out either. I cant see the implementation details of serialisation documents anywhere or just cant find them.

@markwkidd
Copy link
Collaborator

markwkidd commented Sep 2, 2022 via email

@MistyDreams
Copy link
Contributor

MistyDreams commented Sep 2, 2022

@markwkidd I have searched this and in older versions of RA the calls are made however something has changed on the condition of these fallbacks.

this is the only relevant info I can see.

https://docs.libretro.com/development/cores/developing-cores/#retro_serialize_size-retro_serialize-and-retro_unserialize

retro_serialize_size(), retro_serialize(), and retro_unserialize() do not log any output on log_cb it is possible this is too early for the logging system to be implemented though so i also tried printf to no avail to these functions being called.

all i get is
[ERROR] Rewind unavailable because this core lacks serialized save state support. Ill need to trace this to find the condition as it documented as retro_serialize_size() should be called.

I also added
savestate = "true"
savestate_features = "serialized"

to the .info file as per
https://github.com/libretro/RetroArch/blob/6226d0442f324d1c6adc9e2e87684d45a5edc900/core_info.c#L1846-L1872

@MistyDreams
Copy link
Contributor

MistyDreams commented Sep 2, 2022

Ok seem to be making progress after looking at the code its a core info cache issue. I just turned it off at Settings > Core > Cache Core Info Files

savestate = "true"
savestate_features = "serialized"

will need to be added for the .info file for plus. start 1943 rewind seems to work for this game. The try the auto loads again.

some work needs done on this neogeo(if used too soon) and flying shark have issues

@schmurtzm
Copy link
Author

Hi again, thanks again for your investigation :)

I have added the 2 config parameters in mame2003_plus_libretro.info and disabled "Cache Core Info Files" but I still have the same texture problem when I autoload 1943.

Here my RA config file + info core file + core override config :
RA.zip

@MistyDreams
Copy link
Contributor

test rewind an see if that works for you also make sure any previous saves where deleted.

if reind does work

change
memory_descriptors = "false"
libretro_saves = "false"

as true.

if rewind is working i dont see why auto load isint but the could be initialization issues. At least we are at a point we can start debugging it

@MistyDreams
Copy link
Contributor

pacman seems to have fewer issues still has some though still have to check if auto load uses serialization though

@schmurtzm
Copy link
Author

change
memory_descriptors = "false"
libretro_saves = "false"

Where ? In retroarch.cfg ?

I tried, rewind works but I still have the same result 😞

@MistyDreams
Copy link
Contributor

its ok I tested myself get the same result for 1943. The file was the .info file again, Right now i need to get the original mame 078 to compile and fix the issues i had last time. This will let me know if our driver save states are good so i can debug RA end of things.

@schmurtzm
Copy link
Author

schmurtzm commented Sep 2, 2022

I tested myself get the same result for 1943.

Same result as me ? You mean that you have the black screen too ?
This 078 debugging is a little esoteric for me but do not hesitate if I can help for something 😉

@MistyDreams
Copy link
Contributor

yea black screenwith scores and energy bar. The rest will take a while but it could be worth looking into

@schmurtzm
Copy link
Author

Great that you reproduce.
Yes, I can't imagine the complexity of states loading in RA with Mame2003+ as core 😅 I'll be patient 😉

@MistyDreams
Copy link
Contributor

I did test netplay for giggles and ironically it does work you just need to add the analog descriptors. You would need to sacrifice the flexible input system for if conditions to set maps per game like fbneo(libretro port only) does.

Only problem is these remaps don't translate well to anything that isint a gampad layout. Again its a libretro port so they can do as they please but I wouldn't be interested in pursuing it. I have megadrive 6 button pads and arcade sticks so that not something I personally would want for the sake of netplay. Ill let you know if I make any progress on this issue, don't expect it too soon though depends on work and free time.

@schmurtzm
Copy link
Author

Making netplay on this core is a real feat 😅

Ill let you know if I make any progress on this issue, don't expect it too soon though depends on work and free time.

That's OK, I'm already happy that you take a look on this issue. For now we have released our new version OS for Miyoo Mini with auto save state disabled for arcade. If one day you have a great news it will be a good surprise for the numerous arcade gamers 😉 Thank you !

@MistyDreams
Copy link
Contributor

MistyDreams commented Sep 2, 2022

You should consider fbalpha if fbneo is too slow for older hardware(struggles on quiet a bit unless you have a pi 4). I believe netplay and autosave works for that core. If the hardware if good enough use fbneo instead of fba.

ps that project looks very interesting!

@MistyDreams
Copy link
Contributor

Little update rewind is possible with an init fix and driver updates if required millage will vary.

Autoload/Save will need more fixing again possible general but a load of work would be required.

Later mames certainly have better savestate support and current mame can 100% do rewind for games with savestate support added properly.

@schmurtzm
Copy link
Author

I don't know if your last commits concern this problem. I'm going to build it to make some tests 😃
Thanks for your investigations and feedback !

@MistyDreams
Copy link
Contributor

wont help the problems more work needs done newer mames arent an issue though if implemented properly. if hooked up properly soundcore, cpu cores drivers, video ect on this core it could be fixed too much work to go through every gave that needs fixing for me. rewind support is less intensive that autoload for support but still lots of work.

@mahoneyt944
Copy link
Collaborator

mahoneyt944 commented Sep 9, 2022

@MistyDreams hey I asked Jd about this, and he said this:

It sounds like mame2003 doesn't have complete save state support....
When auto load state is enabled, RA loads the state directly after `retro_load_game()` - it seems that some mame drivers need one or more `retro_run()` calls before the state can actually be loaded

What if we run a frame before leaving retro_load_game()?

@barbudreadmon
Copy link
Contributor

What if run a frame before leaving retro_load_game()?

@mahoneyt944 That was one of my previous suggestions, but you might need a database to know exactly how many frames a given game needs before MAME2003+ is ready to accept its savestates. It's also more of a workaround than a fix as it's not really required (FBNeo doesn't do this).

@MistyDreams
Copy link
Contributor

MistyDreams commented Sep 9, 2022

What if run a frame before leaving retro_load_game()?

The simple answer is you need to reset the cpus(init) before entering the run loop(that sets the save states for the cpu). This is originally in the mame run loop which was re factored. It was changed to start init after the retro run call.

Its nothing to do with with how many frames that have run. If a games like neogeo and rtype have save state support it will work. I have no idea where barbudreadmon is getting his information from clearly this core is not fbneo. Save sate support can be added where it is needed as far as rewind is concerned. There is no need to run extra frames.

@MistyDreams
Copy link
Contributor

MistyDreams commented Sep 9, 2022

https://github.com/mamedev/historic-mame/blob/54a1619c9596ddbdc58fa345726b493f209c4af8/src/cpuexec.c#L377-L410

as you can see the original mame this is the main loop. Only difference is we need to prepare everything before retro_run is called because save states require a size in ra before retro_run this will apply to all mames

@mahoneyt944
Copy link
Collaborator

I was just guessing that if we were at a point where a frame ran successfully, the machine would also be ready to auto load a savestate. But this is likely not the best way to resolve this as you pointed out.

@MistyDreams
Copy link
Contributor

MistyDreams commented Sep 9, 2022

run maglord autoload will work as neogeo have pretty good save state support. We done some updates might need looked at will possibly be fine for all games.

rtypeleo points out some issues that will need dealt with though autoload will implode on this one as every variable needed has to be set. Im pretty sure is a stray pointer on that one.

RA is also complaining about misalignment on save or load cant remember which. If someone had a request per game it could probably be fixed. 1943 for example probably just needs the video variables accounted for as the cpus are done already.

@barbudreadmon
Copy link
Contributor

I have no idea where barbudreadmon is getting his information from clearly this core is not fbneo

Just so that we are clear, i know absolutely nothing about MAME2003+ libretro implementation, i was just assuming things were done properly, meaning the machine init was done before the first call to retro_run, as it should. That should indeed be your main concern here, and most likely the main culprit behind this.

I doubt that's the only problem though, since the OP apparently can reproduce the problem just by spamming manual load at boot, and i don't think manual load is even available before retro_run has been called at least once.

@MistyDreams
Copy link
Contributor

yes like i said save state support would need added to that game. You have little to no knowledge of whats going on in this core. Try reading what i posted you might see thats been said already.

@barbudreadmon
Copy link
Contributor

I was talking to @mahoneyt944 because what he said was pretty much what i previously said.
As a rule of thumb, i ignore your posts whenever possible, so sorry that i didn't saw the one pinpointing this. You are right, retro_load_game MUST indeed finish initing the machine, reset included.

@MistyDreams
Copy link
Contributor

lol

schmurtzm added a commit to OnionUI/Onion that referenced this issue Nov 5, 2022
Now a savestate will be done when we exit a mame game but it still not be restored automatically : to avoid bugs (libretro/mame2003-plus-libretro#1433) it is better to let the user load the savestate manually once the game is totally launched.
Aemiii91 added a commit to OnionUI/Onion that referenced this issue Nov 9, 2022
* Update .atari800.cfg

typo fix : ATARIOSA.ROM in upcase , atari800 core is not key sensitive with bios.

* Update OpenBOR with Steward-Fu version

Shrinked version of  OpenBor from Steward-Fu (openbor_20220422) :
Doesn't requires Parasyte framework, only essential files have been kept.

* Amiga replace puae core with puae 2021

Recommended for low hardware, should fix slowdowns with parallax scrolling effect games and fixes a lot of things like compatibility and auto-zoom mode.
Chd files now works perfectly.

Builded from https://github.com/libretro/libretro-uae/tree/2.6.1
Commit c68404cf2e83f1136a45b7b3d3f775c619d9d35f   (Sep 12, 2022)

* add amiga capsimg.so (ipf library)

capsimg.so is required to load .ipf roms

This one is compatible and comes from :
https://github.com/midwan/amiberry/releases/download/v2.25/amiberry-rpi-v2.25.zip

* Mutualize libraries from Parasyte framework

Centalize libraries from Parasyte (credits : Steward-Fu), only the one required for :
 - OpenBor
 - Sorr
 - FFplay

Modify launch.sh from OpenBOR to use this new libraries path.

* Default core configuration for Atari800

Improve game compatibility, credits ilmenit
https://discord.com/channels/529983248114122762/931367023588569180/1035795510080049242

* add FFplay (video player) to Apps

Based on Steward-Fu's FFmpeg :
https://github.com/steward-fu/miyoo-mini/releases

Modified by BoboTraX
https://discord.com/channels/529983248114122762/1007796369785897090/1017450491384434779

Scripted by Schmurtz :
https://discord.com/channels/529983248114122762/1007796369785897090/1035385517086347334

* Change default GBA emulator gpSP -> mGBA

- Switch gpSP and mGBA :
mGBA is now the default GBA emulator, replacing gpSP for better compatibility.
gpSP remains available in the expert section, you won't lose any saves or states.
- new gpSP icon for expert section
- new launch script for mGBA : informs of the change and propose to migrate gamesaves.

* add pico8 / Fake-08 libretro core

- add libretro fake08 core v0.0.2.19
- standalone version updated and moved to expert section
- new icone for standalone version

* Update ScummVM core to 2.7

1 - Games are now automatically imported in Onion thanks to a new importing script created by Onion's Team : no manual shortcuts to create !
2 - The shortcuts created are now .target and respect the recommendations from the ScummVM team to run a game and have the right configuration applied.
3 - A new very important option has been added to the core : "Target FPS for stutter reduction"  allows to run some heavy games with less audio stuttering on the Miyoo Mini. Default value is 55fps and correspond to an audio buffer of about 800 set it to 20 or 30 fps to obtain a buffer of 2000 which helps with heavy games  like Borken Sword 2.5. For Grim Fandango you can set it to 10 or 15.
4 - kyra.dat is now in the right version and allow to run westwood games without problem
5 - The list of compatible games is now a lot bigger and include titles like Grim Fandango or Borken Sword 2.5.

* Update DOSBox Pure to 0.9.7

No more limitation to 16 keyboard bindings with mouse mode.
(DOSBox Pure main author made a workaround in version 0.9.0, but the Mini still runs an older core.)
https://discord.com/channels/529983248114122762/891336865540620338/1029039263922274395

* update PCSX-ReARMed core & standalone

- based on last pcsx commit (4134c62)
- Improve the game compatibility on standalone thanks to the update : now colin 2.0 runs correctly.
- Some little improvements in configuration

* Update gambatte_libretro.so

- update to the last libretro commit  (7e02df60048db0898131ea365f387a026e4e648d)
- shorter time of palette change notification (cf. libretro/gambatte-libretro#238)

* disable color correction on GB / Gambatte

To avoid "super washed out image"

https://www.reddit.com/r/MiyooMini/comments/xgu5cy/comment/ioviaev/?utm_source=share&utm_medium=web2x&context=3

https://discord.com/channels/529983248114122762/1007796369785897090/1020966387801391105

* update vice x64 / Commodore Core

update from af699397ba7b44dc48316277f1a7a24c845f7935
to af699397ba7b44dc48316277f1a7a24c845f7935

https://github.com/libretro/vice-libretro

* Update MAME 2003-Plus.cfg

Now a savestate will be done when we exit a mame game but it still not be restored automatically : to avoid bugs (libretro/mame2003-plus-libretro#1433) it is better to let the user load the savestate manually once the game is totally launched.

* Update PCSX_rearmed to 7e6d030

- Update PCSX_rearmed (libretro core and standalone) as last commits include some game fix.
- Update PCSX-ReARMed.cfg to use SDL audio instead of OSS : it allows to activate auto frameskip in a easier way for users.

* Update scummvm_libretro.info

https://github.com/libretro/libretro-super/blob/master/dist/info/scummvm_libretro.info

* add M.B.A-mini core

Following this issue :
#598

(Great for IREM M92 games )

Core added from this release :
https://github.com/wonder199999/MBA.mini-libretro/releases/tag/05-15-2019

(mba.mini_linux_generic_arm_hardfloat.tar.gz)

* Add PDF viewer (Green)

Add a PDF viewer based on Green pdf reader :
https://github.com/schandinat/green

Version compiled for the Miyoo Mini by Steward-Fu :
https://github.com/steward-fu/miyoo-mini/releases/tag/stock

Add required libraries for Green from Parasyte framework

Add icon for PDF viewer and better icon for FFplay

Little bug fix in FFplay launcher script.

* Update ZX Spectrum core (Fuse) to 3f9344d

- From commit 3371042 to 3f9344d
- Contains fix, support zip files, support map keyboard arrow keys to Spectrum keyboard
- Save states still compatible

* Update Amiga core (puae 2021)

- Update puae 2021 - v2.6.1 from commit c68404c to 1ca4048
https://github.com/libretro/libretro-uae/tree/2.6.1
- Add RAW floppy extension
- Save states still compatible

* Update mame2003_plus_libretro.so

- Update mame2003-plus from commit 8f1498ff to 4bf97d5
https://github.com/libretro/mame2003-plus-libretro
- Many fixes on various games
- Save states are not compatible with previous version !!!

* mGBA : R2 to fast forward & configs

Include modified mGBA core version which allows to map R2 to fast forward (without pressing hotkey). Still based on 0.10.0 (ec5ecb2)

Used repo :
libretro/mgba@99387c0

Issue / Official Feature Request :
on the core : libretro/mgba#273
on retroarch frontend : libretro/RetroArch#14590

-----
some config updates :
- Update mGBA.cfg to use SDL audio instead of OSS : it allows to activate auto frameskip in a easier way for users.
- activate color correction by default for GBA games

* details fixes

- Update mGBA.cfg to use SDL audio instead of OSS : it allows to activate auto frameskip in a easier way for users.
- enable mGBA rumble by default
- little fixes

Co-authored-by: Schmurtz <Schmurtz@gmail.com>
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

No branches or pull requests

5 participants