libretro / parallel-n64

Optimized/rewritten Nintendo 64 emulator made specifically for Libretro. Originally based on Mupen64 Plus.
328 stars 128 forks source link

replace __ARM_NEON__ with HAVE_NEON ? #195

Open barbudreadmon opened 9 years ago

barbudreadmon commented 9 years ago

Would be nice to replace all those __ARM_NEON__ with HAVE_NEON. From what i understood in gizmo98's fork, it seems like neon is the reason why the core built by this repo won't run properly on rpi2, and you have to fully disable neon optimization to build a usable mupen64-libretro core on rpi2.

inactive123 commented 9 years ago

Why wouldn't Raspberry PI 2 support NEON?

barbudreadmon commented 9 years ago

I don't know for sure what's happening, but when i use this repo, even with a custom Makefile including this :

else ifneq (,$(findstring rpi,$(platform))) TARGET := $(TARGET_NAME)_libretro.so LDFLAGS += -shared -Wl,--version-script=$(LIBRETRO_DIR)/link.T fpic = -fPIC GLES = 1 GL_LIB := -L/opt/vc/lib -lGLESv2 INCFLAGS += -I/opt/vc/include ifneq (,$(findstring rpi2,$(platform))) CPUFLAGS += -DNO_ASM -DARM -Darm -DARM_ASM -D__NEON_OPT -DNOSSE HAVE_NEON=1 else CPUFLAGS += -DARMv5_ONLY -DNO_ASM endif PLATFORM_EXT := unix WITH_DYNAREC=arm

mupen64 won't work properly. Disabling every neon optimization, including those automaticaly selected by gcc, is the only way i got a working core.

barbudreadmon commented 9 years ago

mupen64plus-libretro crash with this error on rpi2 when neon enabled : Retroarch [ERROR] :: alsa_worker_thread :: [ALSA]: Unknown error occured (Invalid argument). * Error in `/usr/games/bin/retroarch' : free(): invalid pointer: 0x020aea88 *

barbudreadmon commented 9 years ago

Seems like i said some stupid things, apart from disabling neon on rpi2, https://github.com/gizmo98/mupen64plus-libretro got other differences with this repo.

barbudreadmon commented 9 years ago

Here are my core options for mupen64 : mupen64-gfxplugin = "rice" mupen64-gfxplugin-accuracy = "low" mupen64-screensize = "640x480" mupen64-cpucore = "dynamic_recompiler" mupen64-astick-deadzone = "15" mupen64-pak1 = "none" mupen64-pak2 = "none" mupen64-pak3 = "none" mupen64-pak4 = "none" mupen64-disable_expmem = "enabled" mupen64-rspplugin = "auto" mupen64-filtering = "automatic" mupen64-polyoffset-factor = "-3.0" mupen64-polyoffset-units = "-3.0" mupen64-angrylion-vioverlay = "disabled" mupen64-virefresh = "1500" mupen64-framerate = "original"

steevp commented 9 years ago

The issue seems to only happen on Raspbian. If you use an ARMv7 distro like Arch Linux ARM, the core works on the Pi 2 with HAVE_NEON=1

barbudreadmon commented 9 years ago

I'm not using raspbian, i'm using gentoo.

barbudreadmon commented 9 years ago

What's the "gcc -v" on Arch Linux ?

steevp commented 9 years ago

gcc -v:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/armv7l-unknown-linux-gnueabihf/4.9.2/lto-wrapper
Target: armv7l-unknown-linux-gnueabihf
Configured with: /build/gcc/src/gcc-4.9-20141224/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://github.com/archlinuxarm/PKGBUILDs/issues --enable-languages=c,c++,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-cloog-backend=isl --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --disable-multilib --disable-werror --enable-checking=release --host=armv7l-unknown-linux-gnueabihf --build=armv7l-unknown-linux-gnueabihf --with-arch=armv7-a --with-float=hard --with-fpu=vfpv3-d16
Thread model: posix
gcc version 4.9.2 20141224 (prerelease) (GCC) 

Also I spoke too soon. I just realized that sound isn't working at all with NEON enabled

barbudreadmon commented 9 years ago

That means every "#if defined(ARM_NEON)" is ignored, correct synthax for gcc-4.9 is "#if defined(ARM_NEON)" and mupen64plus-libretro only include synthax for gcc <= 4.8 (that's another reason why replacing ARM_NEON__ by HAVE_NEON would be a good thing, it would be more consistent over gcc versions). Your core has neon almost fully disabled.

steevp commented 9 years ago

Hmm __ARM_NEON__ definitely seems to be defined

The following C code doesn't throw any errors:

#ifndef __ARM_NEON__
#error __ARM_NEON__ is not defined
#endif
barbudreadmon commented 9 years ago

That's quite strange, i've read a lot about gcc-4.9 ignoring those __ARM_NEON__ .

barbudreadmon commented 9 years ago

I still can't get a working core with HAVE_NEON=1 and gcc-4.9, but i get a working core (with sound) with gcc-4.8, gcc-4.9, HAVE_NEON = 0 and the new pull request i did on this repo. I was wondering, what's your CFLAGS when building ?

steevp commented 9 years ago

I used -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard

barbudreadmon commented 9 years ago

-O2 ?

barbudreadmon commented 9 years ago

Same for CXXFLAGS ?

steevp commented 9 years ago

Yes, -O2

CXXFLAGS were the same

barbudreadmon commented 9 years ago

Building with HAVE_NEON=1 and DEBUG=1 gives me those errors : glGetError 0x500 OpenGL Error code 1280 in 'gles2rice/src/OGLRender.cpp' line 867 glGetError 0x500 OpenGL Error code 1280 in 'gles2rice/src/OGLRender.cpp' line 867 glGetError 0x500 OpenGL Error code 1280 in 'gles2rice/src/OGLTexture.cpp' line 35 glGetError 0x502 OpenGL Error code 1282 in 'gles2rice/src/OGLRender.cpp' line 639 glGetError 0x500 OpenGL Error code 1280 in 'gles2rice/src/OGLGraphicsContext.cpp' line 199 glGetError 0x500 OpenGL Error code 1280 in 'gles2rice/src/OGLTexture.cpp' line 35 glGetError 0x502 OpenGL Error code 1282 in 'gles2rice/src/OGLRender.cpp' line 639 glGetError 0x500 OpenGL Error code 1280 in 'gles2rice/src/OGLGraphicsContext.cpp' line 199 glGetError 0x500 OpenGL Error code 1280 in 'gles2rice/src/OGLRender.cpp' line 914 glGetError 0x502 OpenGL Error code 1282 in 'gles2rice/src/OGLRender.cpp' line 639 glGetError 0x500 OpenGL Error code 1280 in 'gles2rice/src/OGLGraphicsContext.cpp' line 199

From what i understand, 1280 is GL_INVALID_ENUM error and 1282 is GL_INVALID_OPERATION .

barbudreadmon commented 9 years ago

Actually it returns the same errors with neon disabled.

neilmunday commented 9 years ago

So far when using ArchLinux on my RPi2 I have been unable to get any decent frame rates or stutter free sound at all from the core when trying to play MarioKart64. With the rice plugin the graphics in the main menu are garbled. For those that have got it working, can you share your RetroArch settings and also what memory split you are using?

Holzhaus commented 9 years ago

@neilmunday Please retest, there were quite some changes. The "garbled menu graphics" issue has been fixed, framerates are still rather bad.

neilmunday commented 9 years ago

@Holzhaus I have just checked out the latest version of mupen64plus-libretro and RetroArch and compiled them both on my Raspberry Pi 2 but I still get "garbled menu graphics" for MarioKart64 sadly with the Rice graphics plugin.

inactive123 commented 9 years ago

Rice is unfortunately quite hopeless in terms of accurate graphics.

Can you test if Glide64 became a lot quicker on Pi2 though? It should, we made various optimizations. BTW - fiddle around with the 'Gfx accuracy' core option (only used by Glide64) - it goes from Low to Veryhigh.

neilmunday commented 9 years ago

Just tried out glide64 and with MarioKart64 on either "low" or "veryhigh" it was unplayable sadly for me - I could only just about get to the player select screen which struggled to draw on the screen and the core ground to a halt. I am using ArchLinux on my Raspberry Pi 2.

If it helps here is the console output:

RetroArch [WARN] :: patch_content :: Did not find a valid content patch. RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: ROM Database: /home/pi/pes/emulators/BIOS/mupen64plus.ini RetroArch: rarch_log_libretro: [libretro INFO] :: EmuThread: M64CMD_ROM_OPEN RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: MARIOKART64 INI patches applied. RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Goodname: MARIOKART64 RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Headername: MARIOKART64 RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Name: MARIOKART64 RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: MD5: 6C634D0CE7CD99CCCBB4CE8EB837EDB4 RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: CRC: 3e5055b6 2e92da52 RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Imagetype: .z64 (native) RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Rom size: 13893632 bytes (or 13 Mb or 104 Megabits) RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: ClockRate = f RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Version: 1446 RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Manufacturer: Nintendo RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Cartridge_ID: 544b RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Country: USA RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: PC = 80000400 RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Save type: 0 RetroArch: rarch_log_libretro: [libretro INFO] :: EmuThread: M64CMD_ROM_GET_HEADER RetroArch [WARN] :: resolve_extensions :: [GL]: GLES implementation does not have BGRA8888 extension. 32-bit path will require conversion. RetroArch [WARN] :: gl_glsl_init :: [GL]: Stock GLSL shaders will be used. ReadSpecialSettings: DEFAULT RetroArch: rarch_log_libretro: [libretro INFO] :: EmuThread: M64CMD_EXECUTE. RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Memory initialized ReadSpecialSettings: DEFAULT ReadSpecialSettings: MARIOKART64 RetroArch: rarch_log_libretro: [libretro INFO] :: Detected RDRAM size: 007fffff RetroArch: rarch_log_libretro: [libretro INFO] :: GL_RENDERER: VideoCore IV HW RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Starting R4300 emulator: Dynamic Recompiler RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Init new dynarec RetroArch: rarch_log_libretro: [libretro INFO] :: Glide64 ucode = 0x8805ffea RetroArch: rarch_log_libretro: [libretro INFO] :: Microcode 1 - F3DEX 1.XX (Star Fox 64) RetroArch: rarch_log_libretro: [libretro INFO] :: microcheck: old ucode: 2, new ucode: 1 RetroArch [ERROR] :: rarch_log_libretro :: [libretro ERROR] :: RetroArch [ERROR] :: rarch_log_libretro :: [libretro ERROR] :: RetroArch [ERROR] :: alsa_worker_thread :: [ALSA]: Unknown error occured (Input/output error). RetroArch [ERROR] :: audio_driver_flush :: Audio backend failed to write. Will continue without sound. RetroArch: rarch_log_libretro: [libretro INFO] :: EmuThread: co_switch main_thread. RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: Stopping emulation. RetroArch: rarch_log_libretro: [libretro INFO] :: mupen64plus: R4300 emulator finished.

Holzhaus commented 9 years ago
RetroArch [ERROR] :: rarch_log_libretro :: [libretro ERROR] :: RetroArch [ERROR] :: rarch_log_libretro :: [libretro ERROR] :: RetroArch [ERROR] :: alsa_worker_thread :: [ALSA]: Unknown error occured (Input/output error).
RetroArch [ERROR] :: audio_driver_flush :: Audio backend failed to write. Will continue without sound.

This seems to be an audio problem.

inactive123 commented 9 years ago

Well, audio might be falling way behind because of the CPU/GPU being bottlenecked.

Sad to hear that despite the optimization strides we made, there is still a long way to go before Glide64 has the same kind of performance as Rice.

heuripedes commented 9 years ago

@neilmunday see if changing Texture Filtering core option to nearest speeds things up.

neilmunday commented 9 years ago

Thanks for the suggestion. I gave it a try but it didn't make much difference. However, increasing the GPU mem in /boot/config.txt from 128MB up to 512MB did at least allow me to get a race to load but the frame rate and audio were noticeably struggling. I also tried increasing it to 768MB but this did not improve things further. I do appreciate all the work you guys are doing - RetroArch is a fantastic emulation platform. Cheers, Neil.