Closed Jcw87 closed 1 year ago
Works great for the first game loaded, but loading a second game (even for a different system) has the no-video problem. Is there some sort of corresponding "reset" that needs to occur between games?
I used RenderDoc to see why it was failing after a second boot, and it looks like the texture that Dolphin was rendering to gets cleared immediately after rendering was finished. It attempts to bind a framebuffer before the clear, but it ends up binding the same framebuffer it was already rendering to. This appears to be happening inside the dolphin core. I will need to spend some time debugging this further.
Ok, I figured out what is happening. The dolphin libretro code makes use of the framebuffer provided by the frontend by overwriting a framebuffer that dolphin creates and deletes. Deletes being the key word. If I switch cores and load an NES game, dolphin does nothing. When I load the dolphin core a second time, it deletes all of the framebuffers it allocated, including the one that the libretro code overwrote, which means it deletes the framebuffer that was allocated by the frontend. Then, when dolphin allocates the EFB framebuffer, it gets the same handle as the framebuffer used by the frontend.
The obvious question though, is why doesn't this happen in RetroArch? RetroArch calls retro_hw_render_callback::context_destroy when it shuts down dolphin, and RALibretro does not
So, to summarize, there are 2 bugs working together to ruin everyone's fun. The dolphin core destroys a resource that doesn't belong to it, and RALibretro doesn't tell dolphin to clean up the GPU resources when it shuts down.
I added the call to free GPU resources, and now you can boot multiple dolphin games and not get a black screen. There are some graphical glitches that can occur when switching games, which is probably due to more OpenGL state shenanigans, but that is a problem for another time.
This PR fixes rendering in dolphin by calling
glBindSampler(0, 0)
inVideo::postHwRenderReset()