SDL: NativeInitGraphics/NativeShutdownGraphics should run on the emu thread.
This commit is contained in:
parent
583c20991f
commit
c16e397fc6
1 changed files with 19 additions and 9 deletions
|
@ -725,21 +725,26 @@ enum class EmuThreadState {
|
||||||
static std::thread emuThread;
|
static std::thread emuThread;
|
||||||
static std::atomic<int> emuThreadState((int)EmuThreadState::DISABLED);
|
static std::atomic<int> emuThreadState((int)EmuThreadState::DISABLED);
|
||||||
|
|
||||||
static void EmuThreadFunc() {
|
static void EmuThreadFunc(GraphicsContext *graphicsContext) {
|
||||||
setCurrentThreadName("Emu");
|
setCurrentThreadName("Emu");
|
||||||
|
|
||||||
// There's no real requirement that NativeInit happen on this thread.
|
// There's no real requirement that NativeInit happen on this thread.
|
||||||
// We just call the update/render loop here.
|
// We just call the update/render loop here.
|
||||||
emuThreadState = (int)EmuThreadState::RUNNING;
|
emuThreadState = (int)EmuThreadState::RUNNING;
|
||||||
|
|
||||||
|
NativeInitGraphics(graphicsContext);
|
||||||
|
|
||||||
while (emuThreadState != (int)EmuThreadState::QUIT_REQUESTED) {
|
while (emuThreadState != (int)EmuThreadState::QUIT_REQUESTED) {
|
||||||
UpdateRunLoop();
|
UpdateRunLoop();
|
||||||
}
|
}
|
||||||
emuThreadState = (int)EmuThreadState::STOPPED;
|
emuThreadState = (int)EmuThreadState::STOPPED;
|
||||||
|
|
||||||
|
NativeShutdownGraphics();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EmuThreadStart() {
|
static void EmuThreadStart(GraphicsContext *context) {
|
||||||
emuThreadState = (int)EmuThreadState::START_REQUESTED;
|
emuThreadState = (int)EmuThreadState::START_REQUESTED;
|
||||||
emuThread = std::thread(&EmuThreadFunc);
|
emuThread = std::thread(&EmuThreadFunc, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EmuThreadStop() {
|
static void EmuThreadStop() {
|
||||||
|
@ -923,6 +928,9 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
GraphicsContext *graphicsContext = nullptr;
|
GraphicsContext *graphicsContext = nullptr;
|
||||||
SDL_Window *window = nullptr;
|
SDL_Window *window = nullptr;
|
||||||
|
|
||||||
|
bool useEmuThread;
|
||||||
|
|
||||||
std::string error_message;
|
std::string error_message;
|
||||||
if (g_Config.iGPUBackend == (int)GPUBackend::OPENGL) {
|
if (g_Config.iGPUBackend == (int)GPUBackend::OPENGL) {
|
||||||
SDLGLGraphicsContext *ctx = new SDLGLGraphicsContext();
|
SDLGLGraphicsContext *ctx = new SDLGLGraphicsContext();
|
||||||
|
@ -930,6 +938,7 @@ int main(int argc, char *argv[]) {
|
||||||
printf("GL init error '%s'\n", error_message.c_str());
|
printf("GL init error '%s'\n", error_message.c_str());
|
||||||
}
|
}
|
||||||
graphicsContext = ctx;
|
graphicsContext = ctx;
|
||||||
|
useEmuThread = true;
|
||||||
} else if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN) {
|
} else if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN) {
|
||||||
SDLVulkanGraphicsContext *ctx = new SDLVulkanGraphicsContext();
|
SDLVulkanGraphicsContext *ctx = new SDLVulkanGraphicsContext();
|
||||||
if (!ctx->Init(window, x, y, mode, &error_message)) {
|
if (!ctx->Init(window, x, y, mode, &error_message)) {
|
||||||
|
@ -943,6 +952,7 @@ int main(int argc, char *argv[]) {
|
||||||
} else {
|
} else {
|
||||||
graphicsContext = ctx;
|
graphicsContext = ctx;
|
||||||
}
|
}
|
||||||
|
useEmuThread = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since we render from the main thread, there's nothing done here, but we call it to avoid confusion.
|
// Since we render from the main thread, there's nothing done here, but we call it to avoid confusion.
|
||||||
|
@ -956,9 +966,10 @@ int main(int argc, char *argv[]) {
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!useEmuThread) {
|
||||||
NativeInitGraphics(graphicsContext);
|
NativeInitGraphics(graphicsContext);
|
||||||
|
|
||||||
NativeResized();
|
NativeResized();
|
||||||
|
}
|
||||||
|
|
||||||
SDL_AudioSpec fmt, ret_fmt;
|
SDL_AudioSpec fmt, ret_fmt;
|
||||||
memset(&fmt, 0, sizeof(fmt));
|
memset(&fmt, 0, sizeof(fmt));
|
||||||
|
@ -996,8 +1007,8 @@ int main(int argc, char *argv[]) {
|
||||||
int framecount = 0;
|
int framecount = 0;
|
||||||
bool mouseDown = false;
|
bool mouseDown = false;
|
||||||
|
|
||||||
if (GetGPUBackend() == GPUBackend::OPENGL) {
|
if (useEmuThread) {
|
||||||
EmuThreadStart();
|
EmuThreadStart(graphicsContext);
|
||||||
}
|
}
|
||||||
graphicsContext->ThreadStart();
|
graphicsContext->ThreadStart();
|
||||||
|
|
||||||
|
@ -1201,7 +1212,6 @@ int main(int argc, char *argv[]) {
|
||||||
EmuThreadStop();
|
EmuThreadStop();
|
||||||
|
|
||||||
delete joystick;
|
delete joystick;
|
||||||
NativeShutdownGraphics();
|
|
||||||
graphicsContext->Shutdown();
|
graphicsContext->Shutdown();
|
||||||
graphicsContext->ThreadEnd();
|
graphicsContext->ThreadEnd();
|
||||||
graphicsContext->ShutdownFromRenderThread();
|
graphicsContext->ShutdownFromRenderThread();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue