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

[WIP] (WiiU) wut toolchain port/Aroma compatibility #14925

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ashquarky
Copy link
Contributor

Description

This PR ports RetroArch to the wut toolchain, allowing it to be compiled with current devkitPPC tooling. It also changes the core loading and filesystems such that they are compatible with Aroma.

There are a few user-visible changes resulting from this, besides the Aroma compatibility:

  • Core loading now only works on Tiramisu or Aroma CFWs, not classic Mocha or HaxchiFW. Given Tiramisu is a drop-in replacement for these older CFWs this shouldn't pose too much of an issue. Users should make sure they're using an up-to-date version, as the libmocha features RetroArch needs for core loading were only added to Tiramisu after Aroma's release.
  • The new core loading method happens to show a WiiU logo and loading music during a core switch. I am undecided if this is an improvement over the black screens of the existing port.
  • On Tiramisu, quitting RetroArch after loading a core goes to the Wii U Menu, not HBL. This is due to longstanding incompatibility between ProcUI and HBL. On Aroma, quitting to the menu is the expected behaviour.
  • wut has a "socket devoptab" that sits between RetroArch and the underlying socket calls, making them much more POSIX-y and standards-compliant. As a result, all the wiiu-specific networking optimisations are not compatible and have been removed. I have no idea how netplay is affected by the new devoptab. Some of the optimisations could be possible to re-add by overriding __init_wut_socket; such changes are not included in this PR.
  • libfat is now enabled on a best-effort basis for USB drives (Aroma/Tiramisu) and SD card (Tiramisu only). When using RetroArch on Tiramisu, the SD card is sd:/, while on Aroma it's fs:/vol/external01. Users switching between Tiramisu and Aroma may have issues with their config file resulting from this difference.
  • Symbols are no longer included in the crash handler.

Moving to wut should put RetroArch in a much stronger position for its long-term maintainability, since fixes to the Cafe bindings, stock Cafe devoptab, and networking compatibility will no longer have to be applied to RetroArch specifically, and can instead be adopted through wut updates. In addition, new features should be possible, such as multithreading (wut provides c11 threads) and dynamic core loading. Cores can also access the Cafe API in the standard way for homebrew, rather than being required to copy headers ad-hoc into their own source trees.

Related Issues

#14429

Related Pull Requests

The related PRs are the primary reason this is still a draft.

Cores

Due to the removal of -mwup in newer devkitPPC tools, many of the core makefiles need to be changed. -mwup is directly equivalent to -D__wiiu__ -DHW_WUP -ffunction-sections -fdata-sections; though usually the defines can be tweaked a bit. Still need to decide whether -D__wut__ or similar is worth including.

Every core built for wiiu that currently uses -mwup will need to be fixed before merge.

Toolchain

There's a new docker container drafted up here: https://git.libretro.com/quarky/libretro-build-wiiu/-/tree/wut

I've not filed a PR for this yet (I think I have push access to the real libretro-build-wiiu anyway...). The toolchain container will need to be live for the same set of nightlies as this PR's merge - the new tools can't build old RetroArch, and the old tools can't build wut RetroArch. Woohoo!

Reviewers

@LibretroAdmin
@gblues (gblues is a co-author of several of the patches submitted here, massive props!)
@Maschell (in case you have comment on the libfat situation)

@vaguerant
Copy link
Contributor

  • more cores here? Need to audit which ones are affected

I went through the cores checking which ones still had the legacy -mwup flag, here are my results:

mwup

no mwup

  • 81-libretro
  • beetle-lynx-libretro
  • blueMSX-libretro
  • cannonball
  • dosbox-svn
  • drhelius/Gearboy
  • drhelius/Gearsystem
  • ecwolf
  • fbalpha2012
  • fbalpha2012_cps1
  • fbalpha2012_cps2
  • fbalpha2012_neogeo
  • FBNeo
  • fmsx-libretro
  • FreeIntv
  • frodo-libretro
  • fuse-libretro
  • gambatte-libretro
  • Genesis-Plus-GX
  • Genesis-Plus-GX-Wide
  • gong
  • gpsp
  • gw-libretro
  • libretro-2048
  • libretro-atari800
  • libretro-cap32
  • libretro-crocods
  • libretro-fceumm
  • libretro-gme
  • libretro-handy
  • libretro-lutro
  • libretro-o2em
  • libretro-pocketcdg
  • libretro-prboom
  • libretro-uae
  • libretro-uzem
  • libretro-vecx
  • mame2003-libretro
  • mame2003-plus-libretro
  • nbarkhina/numero (not currently offered on Wii U anyway)
  • neocd_libretro
  • NP2kai
  • prosystem-libretro
  • RACE
  • snes9x
  • SquirrelJME/SquirrelJME
  • vitaquake2

@Ploggy
Copy link

Ploggy commented Feb 17, 2023

Thank You VagueRant, FixGB FixNES are both current WiiU Cores ;) Their on the buildbot anyways :)

@Ploggy
Copy link

Ploggy commented Mar 3, 2023

I've edited all the makefiles with -mwup and added the new ffunction-sections -fdata-sections -D__wiiu__ -D__wut__ CFLAGS :)
I haven't compiled all the repo's to make sure they work with the new changes, but the couple I did compile worked.
I'm not the best with github but I can upload the modified repos if you want?

It'll have to be later tho it's late now and I'm shattered :P

@Ploggy
Copy link

Ploggy commented Mar 3, 2023

Do the non -mwup Cores need to be modified also?

EDIT:
Managed to add the changes to my own github :) less awkward than just uploading them to a file upload site ;)
https://github.com/Ploggy?tab=repositories

@Ploggy
Copy link

Ploggy commented Mar 4, 2023

I finished editing ALL the Cores from the list above with the new changes for Aroma. That took a while lol
Still haven't got a clue if they will all compile..

https://github.com/Ploggy?tab=repositories

@ashquarky
Copy link
Contributor Author

Had a discussion with @LibretroAdmin and we're going to try and restructure this so that the old and new buildtypes can coexist to some extent. The goal is still to replace the old toolset eventually but this way we can merge it even with issues remaining and leverage the libretro CI to track progress and make test builds available.

Hopefully with wider testing and more eyes we can work out what's going on with e.g. the very long reported loadtimes.

@Ploggy
Copy link

Ploggy commented May 5, 2023

Had a discussion with @LibretroAdmin and we're going to try and restructure this so that the old and new buildtypes can coexist to some extent. The goal is still to replace the old toolset eventually but this way we can merge it even with issues remaining and leverage the libretro CI to track progress and make test builds available.

Hopefully with wider testing and more eyes we can work out what's going on with e.g. the very long reported loadtimes.

Brilliant, saves me manually compiling all the cores :) There were a handful of cores that failed to compile with the new wut changes but they can be tackled as they show up on the CI test builds?

@DaveyL2013
Copy link

Is this still being worked on?

@vaguerant
Copy link
Contributor

@DaveyL2013 Probably not right this instant due to other projects, but it's not abandoned.

@Ploggy
Copy link

Ploggy commented May 31, 2024

Hi there :) been a while I just for fun tried a couple of the Aroma Cores and I think I may have stumbled onto something....
I just loaded the FBneo Core with a clean Retroarch.cfg (deleted from SD card prior and let RA create it when loading the Core's rpx from the WiiU Menu) and the rpx loaded super fast and loading a game was normal too????

But how can that be it was soo slow before.. and confirmed by others too?
I pressed the home button to quit and noticed the asset icons were all scrambled as if the paths were incorrect, then I went into Settings>Directory and sure enough the paths seemed to have defaulted to sd:/ instead of fs:/vol/external01. Could that be it could it just be the paths defaulting back to sd:/ and causing the slow load times.

I've only tried this a couple times and maybe it's something else entirely, but could someone else give it a try and confirm?
(I'll put a few Aroma Cores here so you can try it yourself)
This assumes you already have Retroarch setup on your SD Card:
Delete your retroarch.cfg and salamander.cfg if present
Put one of the core rpx in the sd:/wiiu folder
Put the rest in the sd:/retroarch/cores folder
Put sd back in your wiiu, load up Aroma and select the rpx you placed in wiiu folder from the wiiu menu
Retroarch should boot up pretty quickly
Load your rom from load content, select core and it too should load up like normal
but when you press the home button it should look as if the assets are missing and if you look in Settings>Directory the paths will show they have defaulted back to the sd:/

and if you attempt to quit RA it will just stay loading and not go back to the wiiu menu (perhaps if I left it long enough it would have loaded back to the wiiu menu?)

The path defaulting may happen when switching to another core? I seemed to be able to load a few games one after another when using the same core.

Hopefully this is something trivial and can be fixed easily so this can finally be merged :P

Extract to SD.zip

EDIT: when it does mess up and the path reverts back to sd:/ I end up powering down the WiiU and deleting the Retroarch.cfg and salamander.cfg from the sd card agian to get it back to normal..

EDIT2: looking at this further it looks like it doesnt actually write any path changes to the retroarch.cfg file, it remains fs:/vol/external01. So that 1 sec when it tries to load sd:/ on core switching is enough to mess retroarch up and needs to hard reset to get it working again.

EDIT3: crappy workaround.. in theory as long as you have the cores rpx files in both the wiiu folder AND the retroarch/cores folder and you quit retorarch and load another core from the wiiu menu instead of retroarch's load core option you should be ok?

  • This still feels weird tho, its not the same errors I was getting a year ago... perhaps a year worth of Aroma updates has fixed some things too :P

EDIT4: The damn SNES CORE!! the Snes Core is messing up things.. As long as I stay away from it I can switch cores fine.. EVEN THROUGH RETROARCH!!! well that's it.. the Aroma port works :D the slow loading must have been to do with Aroma CFW and it must have been fixed over the last year? dunno.. strange.

gblues and others added 5 commits June 3, 2024 21:24
== DETAILS
serial debug and some testing revealed that the cause of the
lockup on exit was because of a deadlock in the HID i/o thread.

solution: explicitly shutdown the HID thread during RetroArch
termination process.
This commit is enough to compile RetroArch using wut and more modern
versions of devkitPPC. Among the requisite ports and bugfixes, the wiiu
code has been switched to use wut's headers (where possible).

There's a handful of headers where RA's are more precise, and these
have been put into the `wiiu/include/` hierarchy mirroring WUT's folder
structure, but with `ra_` prepended to the filename to avoid include
directory priority fighting.

Other changes are related to the header changes:
- update defines to use WUT's new definition
- replace custom integer types with standard ones (eg u8 -> uint8_t)
- remove some workarounds/hacks in favor of more precise handling
  in WUT.

Cut features that will be re-added later:
- Current rpx symbol names in the exception handler
- somemopt networking optimisations
- Core loading
- libfat support - always uses fs:/vol/external01

(WiiU) memory: handle being in the background properly

Quitting on Aroma works a little differently to HBL - we need to use a ProcUI
loop and go into the background before quitting. This patch prepares the MEM1
and bucket allocators so they won't crash when this happens.

(WiiU) aroma: fix conflict with FTPiiU plug-in

== DETAILS
The HID polling thread was written to be run on a single core, and
basically completely occupies it, not allowing any other threads to
run on it.

It turns out, this is a problem in Aroma, because other things can
be running on your cores. For instance, the FTPiiU server thread runs
on the same core as the HID polling thread, which explains why FTPiiU
stopped working when RetroArch was running.

The other problem, is that if FTPiiU is holding the IPC BufPool mutex
when RA is started, a deadlock will eventually happen because RA will
try to acquire the mutex and the FTPii thread, being suspended, won't
be able to release it.

So!

To fix it:
- add a 500-microsecond sleep to the HID polling thread
- update to WUT's HID headers, which makes some minor changes to
  structure member names
subrepo:
  subdir:   "deps/libmocha"
  merged:   "630d9681bc"
upstream:
  origin:   "https://github.com/wiiu-env/libmocha"
  branch:   "main"
  commit:   "630d9681bc"
git-subrepo:
  version:  "0.4.6"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "73a0129"
Users need to be running an updated Tiramisu or Aroma, otherwise we'll fall
back to the standard wut devoptab. Since Aroma ships with plugins that keep
the SD card mounted all the time, we have some restrictions:
- On Tiramisu, use libfat for the USB and SD card
- On Aroma, use libfat for the USB only - stock devoptab for SD card

This makes loading on aroma preeeettty slow.
This commit re-adds core loading support, now compatible with Tiramisu and
Aroma; using a libmocha feature added in those CFWs. Note that this does NOT
work under Haxchi FW, non-payload Mocha versions, etc. RetroArch now requires
either Tiramisu or Aroma on Wii U.

The overall strategy is to make the path of the core to be loaded relative to
the SD card root, pass this off to Mocha, then switch titles to the wrapper
title (usually Health and Safety). In order to pass arguments, sysapp is used,
with a little extra logic (since sysapp passes a blob of arbitrary bytes) to
emulate argc/argv.
@ashquarky
Copy link
Contributor Author

Rebased onto current RetroArch.

@ashquarky
Copy link
Contributor Author

@ashquarky ashquarky force-pushed the wiiu-wut-merge branch 2 times, most recently from 374c2a8 to 892b0ce Compare June 6, 2024 04:56
@ashquarky
Copy link
Contributor Author

That last change changes how RA is packaged, in exchange for greatly improved load times on Aroma, so I'll quickly go over that.

  • Salamander is packed alongside the RetroArch assets into a wuhb bundle, roughly ~80MB in all. This goes into sd:/wiiu/apps and is shown on the menu with a generic RetroArch icon. (For those who don't know, Salamander on WiiU just immediately loads the last-used core, it doesn't have any menus or any substantial amount of code at all)
  • Cores are still .rpx files, in sd:/retroarch/cores - not sd:/wiiu/apps, which means they no longer appear on the menu. Everyone will now access RetroArch via Salamander, therefore via the wuhb bundle, which due to how wuhb bundles work means that the assets from that bundle are available to every core. This is where the load speed boost comes from - cores load the menu assets from a single file on SD (the wuhb) instead of lots of small files. This works around inefficiencies in the Cafe OS filesystem drivers.

This does mean that users can't "directly" boot a desired core from the menu, instead going via Salamander and their last-used core, but the core switching speed should be fast enough now that this isn't a big problem.

This also sets us up for a potential future where cores are dynamically-linked .rpls, which will practically eliminate load times altogether by putting all the menu code into Salamander.

Maschell and others added 3 commits June 10, 2024 16:30
Implements support for the Wii U's HOME button menu (HBM). This fixes various "OS integration" warts
(like powering off the console). Now that the HOME button is used for HBM, change the menu bind to
Start+Select.

Various changes are also required for backgrounding support.

Co-developed-by: Maschell <[email protected]>
Users who prefer the old legacy behaviour of the Home button opening the RetroArch menu, they can disable the HBM here.
These assets are shared to the cores after core switch. Reading them out of a .wuhb is an Aroma-exclusive feature that makes core loading times dramatically better.

Branding assets provided by @Ploggy, originally by cucholix afaik.

Co-developed-by: Maschell <[email protected]>
@ashquarky
Copy link
Contributor Author

Adding ProcUI/HBM support brings RetroArch in line with official Wii U software as well as all Aroma homebrew. It does create a conflict over the HOME button - it now opens the OS's built in HOME menu overlay rather than the RetroArch menu. To smooth this over, the RetroArch menu is opened alongside the HOME menu so users can access it when they return, and the default "open menu" binding is changed to Start+Select, as it is on the Switch.
For users who prefer the old behaviour, it can still be accessed by disabling Settings -> Input -> Menu -> Allow Wii U HOME menu.

Some users like to use native-format drives to store their data alongside Wii U games. Use libmocha to support this.

Note Mocha_MountFS claims success even if the mounted folder doesn't exist.

Since Salamander only has a "minimal" version of libmocha without the MountFS functionality, undefine HAVE_LIBMOCHA in that build. Users may want to build without MountFS but can't reasonably build without RPX loading.
@ashquarky
Copy link
Contributor Author

Does anyone know where https://docs.libretro.com/development/retroarch/compilation/wiiu/ are written up? In Git somewhere? I may have to update them if this merges due to the new toolchain

@vaguerant
Copy link
Contributor

Does anyone know where https://docs.libretro.com/development/retroarch/compilation/wiiu/ are written up? In Git somewhere? I may have to update them if this merges due to the new toolchain

https://github.com/libretro/docs/blob/master/docs/development/retroarch/compilation/wiiu.md

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

Successfully merging this pull request may close these issues.

6 participants