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

RetroArch core issues #9936

Closed
inactive123 opened this issue Aug 28, 2017 · 26 comments
Closed

RetroArch core issues #9936

inactive123 opened this issue Aug 28, 2017 · 26 comments
Labels
Libretro Issue on Libretro but not all ports.

Comments

@inactive123
Copy link
Contributor

inactive123 commented Aug 28, 2017

Hi there,

We are making a new libretro core for PPSSPP, this time with the intent of making it upstreamable.

We are currently hitting a blocking issue with the GL driver. We need to be able to override the backbuffer ID so that it points to an FBO, so that the final blit is being done to a FBO instead of the backbuffer. With libretro GL, a 'backbuffer' FBO gets made available to the core and the core should use it from that point on instead of the code just rendering to the backbuffer.

You can see here what ToadKing added to the code years ago -

https://github.com/libretro/libretro-ppsspp/commit/f30e7df7ef262a47e65767285d56e0016e797484

Apparently, Unknown tells me this is an issue on iOS too, and that there currently exists a hackish solution for it.

If this could be implemented in upstream, I could continue with the core. So far, I have it logging the main loop and __AudioMix seems to be returning a value (indicating it's processing some audio samples). Right now, rendering is not implemented yet, so I hope that when this gets added to upstream, we wil lfinally be able to output a picture.

Just for the sake of reference, I'm currently working on the new core port here -

https://github.com/twinaphex/ppsspp

@hrydgard
Copy link
Owner

OK, that looks like a good start. I'll look into making the iOS hack a bit more generic so you can use it.

@inactive123
Copy link
Contributor Author

inactive123 commented Aug 28, 2017

Awesome! Thanks a lot.

BTW, I am trying to see if I can get any output with the software renderer - I see these errors right now when trying to use the software renderer -

https://hastebin.com/puzexaneda.pas

Am I missing any compile-time defines for making the dynarec PIC-compliant?
EDIT: Hmm, seems to happen with Cpucore::INTERPRETER too. So it might not be a PIC issue. I don't get these WriteRest op out of range errors at least when using Gpucore::GLES.

I am trying to base the libretro port so far on the Headless target, so there is no NativeApp/UI being used.

@hrydgard
Copy link
Owner

hrydgard commented Aug 28, 2017

It does seem from another reported issue that we're failing PIC-compliance somewhere. If you can breakpoint there and get a good callstack, I can fix it very quickly.

For bringup, you can enable the interpreter.

hrydgard added a commit that referenced this issue Aug 28, 2017
@hrydgard
Copy link
Owner

Added a quick FBO override.

@inactive123
Copy link
Contributor Author

inactive123 commented Aug 28, 2017

Thanks, I will try to get that hooked up on the libretro side.

As for the potential PIC issues, I get those errors with the software renderer when setting the CPU core to either Interpreter or JIT. Anyway, I will try hooking up the FBO override first.

@hrydgard
Copy link
Owner

hrydgard commented Aug 28, 2017

Oh, then it's probably the vertex decoder JIT. That can be turned off as well.

g_Config.bVertexDecoderJit = false

@inactive123
Copy link
Contributor Author

inactive123 commented Aug 28, 2017

Hi there, is there also an equivalent for this function that I could use?

' fbo_create_from_native_fbo

https://github.com/libretro/ppsspp-native/blob/9baedbcc2a07b3bccc6d8b8d170498111b990adc/gfx_es2/fbo.cpp#L252

We used that here after initializing PPSSPP - and before we enter the main loop -

https://github.com/libretro/libretro-ppsspp/blob/master/libretro/libretro.cpp#L1130

Or is this no longer necessary? I should simply use the GLuint from the libretro framebuffer ?

@inactive123
Copy link
Contributor Author

inactive123 commented Aug 28, 2017

OK, I now get a crash here -

libretro-mirrors@2a0bf22

(gdb) bt
#0 0x00007f781b3c97c5 in Draw::CreateShader (draw=0x350c1d2310, stage=Draw::ShaderStage::VERTEX, sources=std::vector of length 4, capacity 4 = {...}) at ../ext/native/thin3d/thin3d.cpp:260
#1 0x00007f781b3c9917 in Draw::DrawContext::CreatePresets (this=this@entry=0x350c1d2310) at ../ext/native/thin3d/thin3d.cpp:271
#2 0x00007f781b3caf77 in Draw::OpenGLContext::OpenGLContext (this=0x350c1d2310) at ../ext/native/thin3d/thin3d_gl.cpp:597
#3 0x00007f781b3cb6db in Draw::T3DCreateGLContext () at ../ext/native/thin3d/thin3d_gl.cpp:1192
#4 0x00007f781b56f67f in retro_run () at ../libretro/libretro.cpp:1190
#5 0x000000350728fe40 in core_run () at core_impl.c:415
#6 0x0000003507295127 in runloop_iterate (sleep_ms=0x7ffc0687093c) at retroarch.c:3076
#7 0x000000350728ece0 in rarch_main (argc=, argv=, data=0x0) at frontend/frontend.c:131
#8 0x00007f78332c44ca in __libc_start_main () from /usr/lib/libc.so.6
#9 0x000000350728c01a in _start ()

@hrydgard
Copy link
Owner

You shouldn't need fbo_create_from_native_fbo, right?

Is draw = null there for some reason?

@inactive123
Copy link
Contributor Author

Yeah, I hope I won't need that function.

I am only setting coreParam.thin3d here - is that not enough?

https://github.com/twinaphex/ppsspp/blob/master/libretro/libretro.cpp#L1189

@inactive123
Copy link
Contributor Author

inactive123 commented Aug 28, 2017

Yeah, I have GetDrawContext just return NULL. I honestly don't know what is supposed to be done there or why we need all these abstractions now when they weren't there back in 2015.

I also see no real good reference implementations from a headless perspective that I could base this new port on -

https://github.com/twinaphex/ppsspp/blob/master/libretro/libretro.cpp#L97

@inactive123
Copy link
Contributor Author

inactive123 commented Aug 28, 2017

Can't I just point DrawContext stuff to NULL? Libretro shouldn't really need this kind of drawcontext, all buffer swaps happen at the frontend level, no need to set swap interval either, its all frontend-bound.

@hrydgard
Copy link
Owner

Back then PPSSPP didn't support so many backends.

The GraphicsContext with swapbuffers you can just stub.

thin3d is an abstraction used for drawing the UI using the same code for all the backends (GL, D3D9/11, Vulkan). You don't need it for that because you'll presumably skip the PPSSPP UI. But, we also use it for framebuffer management in the emulator to be able to share the rather complex framebuffer management code without creating YET another absraction layer. This is not really architecturally super-clean, but that's the way it is currently. So you still need to spawn the appropriate thin3d context for that reason.

That should not be an issue though, it should easily work.

@hrydgard
Copy link
Owner

You can skip the CreatePresets stuff though, it's only used for drawing UI IIRC.

@inactive123
Copy link
Contributor Author

if I stub out the CreatePresets function call invocation, it crashes here instead -

Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00007f11333cc578 in Draw::OpenGLContext::BlitFramebuffer (this=0x25dc5b1120, fbsrc=0x0, srcX1=-1089252096, srcY1=-596581248, srcX2=1, srcY2=-596582032, fbdst=0x0, dstX1=963834945, dstY1=6,
dstX2=1077014528, dstY2=2, channels=0, linearFilter=Draw::FB_BLIT_NEAREST) at ../ext/native/thin3d/thin3d_gl.cpp:1658
1658 fbo_bind_fb_target(false, dst->handle);
[Current thread is 1 (Thread 0x7f1152696880 (LWP 27405))]
(gdb) bt
#0 0x00007f11333cc578 in Draw::OpenGLContext::BlitFramebuffer (this=0x25dc5b1120, fbsrc=0x0, srcX1=-1089252096, srcY1=-596581248, srcX2=1, srcY2=-596582032, fbdst=0x0, dstX1=963834945, dstY1=6,
dstX2=1077014528, dstY2=2, channels=0, linearFilter=Draw::FB_BLIT_NEAREST) at ../ext/native/thin3d/thin3d_gl.cpp:1658
#1 0x00007f1133335ac6 in FramebufferManagerCommon::SetNumExtraFBOs (this=this@entry=0x25dc6fb2b0, num=num@entry=0) at ../GPU/Common/FramebufferCommon.cpp:191
#2 0x00007f11333949ed in FramebufferManagerGLES::CompilePostShader (this=this@entry=0x25dc6fb2b0) at ../GPU/GLES/FramebufferManagerGLES.cpp:102
#3 0x00007f11333953e6 in FramebufferManagerGLES::CompileDraw2DProgram (this=0x25dc6fb2b0) at ../GPU/GLES/FramebufferManagerGLES.cpp:97
#4 0x00007f1133396242 in FramebufferManagerGLES::Init (this=0x25dc6fb2b0) at ../GPU/GLES/FramebufferManagerGLES.cpp:213
#5 0x00007f113338d29a in GPU_GLES::GPU_GLES (this=0x25dc62c700, gfxCtx=, draw=0x25dc5b1120) at ../GPU/GLES/GPU_GLES.cpp:101
#6 0x00007f11333708f8 in GPU_Init (ctx=0x25d9d9f450, draw=0x25dc5b1120) at ../GPU/GPU.cpp:68
#7 0x00007f1133565303 in PSP_InitUpdate (error_string=0x7ffdbf1358f0) at ../Core/System.cpp:448
#8 0x00007f1133565361 in PSP_Init (coreParam=..., error_string=error_string@entry=0x7ffdbf1358f0) at ../Core/System.cpp:466
#9 0x00007f113356f64f in retro_run () at ../libretro/libretro.cpp:1191
#10 0x00000025d6d06e40 in core_run () at core_impl.c:415
#11 0x00000025d6d0c127 in runloop_iterate (sleep_ms=0x7ffdbf1359ec) at retroarch.c:3076
#12 0x00000025d6d05ce0 in rarch_main (argc=, argv=, data=0x0) at frontend/frontend.c:131
#13 0x00007f1149d034ca in __libc_start_main () from /usr/lib/libc.so.6
#14 0x00000025d6d0301a in _start ()

@inactive123
Copy link
Contributor Author

So I can get it to work with -O0, -O2 still produces the crash you can see.

Anyway, as discussed on IRC, here are some details on how to get RetroArch compiling for Linux -

This should be our official instructions for compiling RetroArch itself -

http://buildbot.libretro.com/docs/compilation/ubuntu/

Now, as for compiling the core itself -

do a git clone --recursive of my fork -

https://github.com/twinaphex/ppsspp.git

Once done, go to the directory 'libretro'. Run 'make'. When it's done, you should have a ppsspp_libretro.so file. This is the dynamic library core. You need to put that in RetroArch's cores directory.

BTW, I am always online on IRC at freenode, so definitely hit me up if you have any further questions.

@hrydgard
Copy link
Owner

I checked out and built retroarch in ~/retroarch, then built and copied ppsspp_libretro.so to ~/retroarch/cores/ , but when I run ./retroarch in ~/retroarch and choose Load Cores, it's not in the list. Any ideas?

@hrydgard hrydgard changed the title Override the backbuffer for final blit RetroArch core issues Aug 29, 2017
@hrydgard
Copy link
Owner

Fixed one PIC bug, not sure if it'll do the trick: 8d04983

@inactive123
Copy link
Contributor Author

Hi there, not sure if the Cores issue is still a problem, but in case it is -

You can go to Settings -> Directory. Look at what 'Core Dir' is set to. Your cores need to be placed there. You canalso change the path from that screen.

@unknownbrackets
Copy link
Collaborator

unknownbrackets commented Aug 30, 2017

If you're still getting that crash, it may be worth adding something like:

bool OpenGLContext::BlitFramebuffer(Framebuffer *fbsrc, int srcX1, int srcY1, int srcX2, int srcY2, Framebuffer *fbdst, int dstX1, int dstY1, int dstX2, int dstY2, int channels, FBBlitFilter linearFilter) {
	OpenGLFramebuffer *src = (OpenGLFramebuffer *)fbsrc;
	OpenGLFramebuffer *dst = (OpenGLFramebuffer *)fbdst;
	GLuint bits = 0;
if (dst == nullptr || src == nullptr) {
printf("Goodbye, cruel world.\n");
*(int *)0 = 1337;
}

Just to make sure the backtrace isn't confused. SetNumExtraFBOs() shouldn't be calling BlitFramebuffer(),. I would think...

I also recommend https://stackoverflow.com/a/2220565.

-[Unknown]

@hrydgard
Copy link
Owner

@twinaphex I think I know why Tekken 6 isn't working. First time you run it it shows you a system message dialog, and those aren't working currently because it can't access ppge_atlas.zim from PPSSPP's /assets. That file and compat.ini must be included somehow. Does RetroArch have a system for "system data files"? I guess it must, for BIOSes and so on?

@inactive123
Copy link
Contributor Author

@hrydgard Yes, it has a system directory. The core can get a path to this through an environment variable call.

@webgeek1234
Copy link
Contributor

I made a change to the libretro fork to hook up save states, however I had to move SaveState::SaveStart public to do so. Is there a better way to handle this? A wrapper function that could be used directly without extra modifications? The change I made is below:

libretro@f649ae3

@unknownbrackets
Copy link
Collaborator

You shouldn't call that directly. It looks like you want SaveState::SaveToRam and SaveState::LoadFromRam instead.

-[Unknown]

@hrydgard
Copy link
Owner

How's progress on this? Can we close this issue?

@orbea
Copy link
Contributor

orbea commented Mar 24, 2018

@hrydgard Maybe that its merged now this can be closed? I'd suggest new issues be made for anything more specific. :)

@unknownbrackets unknownbrackets added the Libretro Issue on Libretro but not all ports. label Mar 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Libretro Issue on Libretro but not all ports.
Projects
None yet
Development

No branches or pull requests

5 participants