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

(libretro) context_reset is broken #10784

Open
orbea opened this issue Mar 24, 2018 · 33 comments · Fixed by #10809
Open

(libretro) context_reset is broken #10784

orbea opened this issue Mar 24, 2018 · 33 comments · Fixed by #10809
Labels
Libretro Issue on Libretro but not all ports.

Comments

@orbea
Copy link
Contributor

orbea commented Mar 24, 2018

What happens?

When toggling fullscreen in RetroArch with f ppsspp renders a broken image breaking any game play. I'm told this was broken in an rebase when merging the core upstream?

What should happen?

Toggling full screen should work.

What hardware and operating system are you running PPSSPP on? GPU might matter if it's a graphical issue.

OS: Slackware64-current
GPU: GK110B
mesa-2018.01.18_5fc21c6_master-x86_64-1_git

Related issue: libretro-mirrors#27

@unknownbrackets unknownbrackets added the Libretro Issue on Libretro but not all ports. label Mar 24, 2018
@hrydgard
Copy link
Owner

hrydgard commented Mar 24, 2018

Yeah everything was badly broken for retroarch after the new GL threading rework, then @aliaspider swooped in and fixed it all up except resizing. Needs to be looked into.

@orbea
Copy link
Contributor Author

orbea commented Mar 27, 2018

@aliaspider Thanks for the fix!

@orbea
Copy link
Contributor Author

orbea commented Mar 27, 2018

@hrydgard and @aliaspider, actually this solution doesn't work here...

Instead of displaying garbage emulation gets frozen on a white screen.

@orbea
Copy link
Contributor Author

orbea commented Mar 27, 2018

Additionally apitrace doesn't like it and will exit when trying to toggle context_reset.

apitrace: warning: unknown function "glPolygonOffsetClamp"
apitrace: warning: unknown function "glWindowRectanglesEXT"
I: gpu_features.cpp:142: GPU Vendor : nouveau ; renderer: NVF1 version str: 3.1 Mesa 18.1.0-devel (git-5fc21c6044) ; GLSL version str: 1.40
I: GLRenderManager.cpp:154: Running first frame (0)
apitrace: warning: caught signal 11
apitrace: flushing trace
/usr/bin/../lib64/apitrace/wrappers/glxtrace.so+0x1f588c
/lib64/libpthread.so.0+0x1237f
/usr/lib64/libasound.so.2+0x5f5a3
/usr/lib64/libasound.so.2: snd_pcm_state+0x28
/usr/lib64/libasound.so.2+0x86588
/usr/lib64/libasound.so.2+0x8d952
/usr/lib64/libasound.so.2: snd_pcm_poll_descriptors_revents+0x53
/usr/lib64/libasound.so.2+0x53632
/usr/lib64/libasound.so.2: snd_pcm_wait+0x1a
retroarch+0xdf76d
retroarch+0x3f964
/usr/lib64/libretro/ppsspp_libretro.so: _ZN10CoreTiming21ProcessFifoWaitEventsEv+0x50
/usr/lib64/libretro/ppsspp_libretro.so: _ZN10CoreTiming7AdvanceEv+0x44
/usr/lib64/libretro/ppsspp_libretro.so: _Z18__KernelReSchedulePKc+0x12
?+0x4122e273
apitrace: info: taking default action for signal 11

Full log - https://pastebin.com/u78dMX8E
Trace - http://ks392457.kimsufi.com/orbea/stuff/trace/ppsspp_context_reset.trace.xz

@hrydgard hrydgard reopened this Mar 28, 2018
@orbea
Copy link
Contributor Author

orbea commented Mar 29, 2018

I discovered that the apitrace crash doesn't always occur. I'm not sure what the difference is?

Here is a more informative trace.
http://ks392457.kimsufi.com/orbea/stuff/trace/ppsspp_context_reset2.trace.xz
apitrace log - https://pastebin.com/8uHDiDYw

@orbea
Copy link
Contributor Author

orbea commented Mar 29, 2018

I am guessing this might have to do with how ppsspp and/or RetroArch is trying to set a 3.1 core context, which does not exist according to some mesa devs.

This recently caused issues with beetle-psx, see this issue. libretro/beetle-psx-libretro#315

But if I use export MESA_GL_VERSION_OVERRIDE=3.2 neither the ppsspp libretro core or RetroArch will start (Beetle-psx does...). I also am not sure where either RetroArch or ppsspp are setting a default GL context?

@orbea
Copy link
Contributor Author

orbea commented Mar 29, 2018

RetroArch doesn't start because its using a compat profile apparently. Setting 3.0 or older works while 3.1 or newer doesn't. I supposed 3.1 should be exposed as a compat context in mesa now, but there might be some confusion and bugs around that.

As for ppsspp, I'm still not sure where its setting the GL profile context?

@unknownbrackets
Copy link
Collaborator

You must call SetGLCoreContext(true); when using a core profile context. We by default assume a compatibility profile.

See for example here:

SetGLCoreContext(true);

Do not set it to true under a GLES profile.

-[Unknown]

@orbea
Copy link
Contributor Author

orbea commented Mar 29, 2018

My guess its currently using a non-core compat GL profile as it hits this line.

https://github.com/hrydgard/ppsspp/blob/master/libretro/LibretroGLContext.h#L15

@orbea
Copy link
Contributor Author

orbea commented Nov 14, 2018

Any updates on this issue? It would really be a big benefit for the libretro core if this could be solved.

@orbea
Copy link
Contributor Author

orbea commented Dec 3, 2018

I have just realized that vulkan was hooked up for libretro and that this is not a problem with Vulkan, only OpenGL.

@hrydgard
Copy link
Owner

Is this still an issue?

@orbea
Copy link
Contributor Author

orbea commented Jun 27, 2019

Yes, ppsspp libretro is still completely broken and unusable on linux.

@m4xw
Copy link
Contributor

m4xw commented Jul 5, 2019

I have had simliar issues with my Switch port (it would crash tho, however on recent builds it renders no video and only audio after ctx reset), I figured it was because my hacky temporary GL loader.
@orbea can you provide me with a picture of what the "broken image" looks like?
Maybe this ends up being the same underlying issue.
I will investigate this and other issues over the next weeks and probably rewrite parts of the core impl.
So any infos you can provide me with are very helpful.

@orbea
Copy link
Contributor Author

orbea commented Jul 5, 2019

@m4xw There is not much to show, it starts off a blank white screen and then transitions to a blank black screen as the game proceeds.

@m4xw
Copy link
Contributor

m4xw commented Jul 5, 2019

Ok thanks

@orbea
Copy link
Contributor Author

orbea commented Aug 31, 2019

This is most certainly not fixed in commit 1618aa8.

@BParks21
Copy link

@orbea Sorry about that thought i was commenting on a different issue.

@hrydgard
Copy link
Owner

How bad is this now?

@raidenii
Copy link

raidenii commented Jan 4, 2021

Not sure if it's related - ppsspp libretro core on Linux (tested on x86-64 and aarch64) gives a black screen when starting a 2nd game in the same RA session, like mentioned in #11339.

@BParks21
Copy link

Any news on this issue? Would be nice to be able toggle fullscreen on and off with specific video drivers set. D3D 9 & 11 just crash, glcore goes to a black screen, and vulkan and gl work as expected.

@gouchi
Copy link
Contributor

gouchi commented Aug 1, 2021

Here is some backtrace using glcore video driver toggling full screen.

[libretro INFO] [G3D] Context reset
[libretro ERROR] [SYSTEM] (../GPU/Common/PresentationCommon.cpp:CreateDeviceObjects:443) Critical: [vdata_ == nullptr] *** Assertion ***

(../GPU/Common/PresentationCommon.cpp:CreateDeviceObjects:443) Critical: [vdata_ == nullptr] *** Assertion ***

[libretro INFO] [SYSTEM] *** Assertion ***


Thread 1 "retroarch-debug" received signal SIGINT, Interrupt.
0x00007ffff55b001b in kill () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff55b001b in kill () at /usr/lib/libc.so.6
#1  0x00007fffe41ab4e1 in PresentationCommon::CreateDeviceObjects() () at /tmp/ppsspp/libretro/ppsspp_libretro-debug.so
#2  0x00007fffe4203819 in FramebufferManagerGLES::DeviceRestore(Draw::DrawContext*) () at /tmp/ppsspp/libretro/ppsspp_libretro-debug.so
#3  0x00007fffe41e4d57 in GPUCommon::DeviceRestore() () at /tmp/ppsspp/libretro/ppsspp_libretro-debug.so
#4  0x00007fffe41ffe09 in GPU_GLES::DeviceRestore() () at /tmp/ppsspp/libretro/ppsspp_libretro-debug.so
#5  0x000055555561fc24 in drivers_init (p_rarch=0x555556411a80 <rarch_st>, settings=0x55555657cd50, flags=2047, verbosity_enabled=true) at retroarch.c:33643
#6  0x000055555561be53 in video_driver_reinit_context (p_rarch=0x555556411a80 <rarch_st>, settings=0x55555657cd50, flags=2047) at retroarch.c:31804
#7  0x000055555561bed0 in video_driver_reinit (flags=2047) at retroarch.c:31816
#8  0x00005555555f42af in command_event_reinit (p_rarch=0x555556411a80 <rarch_st>, flags=2047) at retroarch.c:13385
#9  0x00005555555f54f0 in command_event (cmd=CMD_EVENT_REINIT, data=0x0) at retroarch.c:14021
#10 0x00005555555f7131 in command_event (cmd=CMD_EVENT_FULLSCREEN_TOGGLE, data=0x0) at retroarch.c:14862
#11 0x000055555562a30f in runloop_check_state (p_rarch=0x555556411a80 <rarch_st>, settings=0x55555657cd50, current_time=24732700664) at retroarch.c:38025
#12 0x000055555562ced8 in runloop_iterate () at retroarch.c:39067
#13 0x00005555555f8881 in rarch_main (argc=5, argv=0x7fffffffe078, data=0x0) at retroarch.c:15700
#14 0x00005555555f88e3 in main (argc=5, argv=0x7fffffffe078) at retroarch.c:15777
(gdb) info frame
Stack level 0, frame at 0x7fffffff9090:
 rip = 0x7ffff55b001b in kill; saved rip = 0x7fffe41ab4e1
 called by frame at 0x7fffffff9100
 Arglist at 0x7fffffff9080, args: 
 Locals at 0x7fffffff9080, Previous frame's sp is 0x7fffffff9090
 Saved registers:
  rip at 0x7fffffff9088
(gdb) info reg
rax            0x0                 0
rbx            0x555557e304e0      93825035076832
rcx            0x7ffff55b001b      140737309769755
rdx            0x1                 1
rsi            0x2                 2
rdi            0xdf13              57107
rbp            0x555558d60230      0x555558d60230
rsp            0x7fffffff9088      0x7fffffff9088
r8             0x555557e59770      93825035245424
r9             0x7ffff56f84e0      140737311114464
r10            0x7ffff557dfb0      140737309564848
r11            0x206               518
r12            0x5555555d2050      93824992747600
r13            0x0                 0
r14            0x0                 0
r15            0x0                 0
rip            0x7ffff55b001b      0x7ffff55b001b <kill+11>
eflags         0x206               [ PF IF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0

@gouchi
Copy link
Contributor

gouchi commented Aug 1, 2021

@orbea this issue should be renamed to (libretro) context_reset is broken using gl or glcore video driver.

EDIT : Nevermind the issue happens also with d3dxx video driver.

@unknownbrackets
Copy link
Collaborator

Well, I took a quick look at the libretro.c file and it seems like the basic problem is that it calls reset without calling destroy first. I'm not likely to dig into this further, but I suspect the author of LibretroGraphicsContext.cpp was under the impression that ContextDestroy would be called before ContextReset.

It might be as simple as a flag to destroy everything before proceeding with the rest of reset, if destroy was never called.

Looks like this is an expected scenario:
https://github.com/libretro/RetroArch/blob/15d28fe2eb8f8829c7cb792356a3563de2ecb9fa/libretro-common/include/libretro.h#L2472

I'm not very interested in libretro, but it's the first time someone posted a useful stack trace to this issue in 3 years, so figured I'd take a quick look. Hopefully that helps whoever is interested in actually fixing and testing this.

-[Unknown]

@bslenul
Copy link
Contributor

bslenul commented Aug 4, 2021

As an additional info for anyone wanting to take a look at this, as mentioned in #12841 for some reason it doesn't crash if audio sync is OFF... 🤔 Could be completely unrelated however, idk.

Nope nvm, can't reproduce anymore, not sure what happened, maybe I've switched to Vulkan or something during my tests, but seems like it doesn't fix anything... sorry about that :/

@m4xw
Copy link
Contributor

m4xw commented Aug 4, 2021

@bslenul can u check with "enable menu sounds"?

@KamiLordus
Copy link

It seems to me that the current version of PPSSPP performs even worse than a few months ago when it comes to switching fullscreen.
DX11 and Vulcan crash when switching fullscreen in Retro Arch.
Only GL works - but texture filtering doesn't work in this mode, so the graphics are much worse (for example GTA 3 Liberty City Stories).

@hrydgard
Copy link
Owner

What do you mean that texture filtering doesn't work? Seems very bizarre to me.

@KamiLordus
Copy link

Sorry, I wasn't specific enough.
In dx11 mode textures filtering set to auto max quality, gives a very nice anti-aliasing effect.
In GL textures filtering mode auto max in my case does not give a similar result. I tried to capture it in pictures, but without the ability to exit to the desktop (fullscreen switching), it's quite hard to capture the same moment.

GL filtering auto max:
2

DX11 auto max:
1

However, this is not the worst problem.
The problem is that there is no option to switch fullscreen to window mode. Constant RA crash, I think even in GL mode it happened to me

@hrydgard
Copy link
Owner

hrydgard commented Jan 31, 2023

Ah yes, auto max quality doesn't yet autogenerate mipmaps on OpenGL, which is required to get that smooth effect, which I agree is desirable.

As for fullscreen, no idea, as stated many times I'm not maintaining the libretro port, I just review and merge PRs for it as my focus is the standalone build.

@KamiLordus
Copy link

Thanks for the answer. I will try to report this problem in RA liberto. Maybe someone will have an idea.

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

Successfully merging a pull request may close this issue.

9 participants