Change Present to finish only after swap

This commit is contained in:
James Rowe 2019-09-18 10:54:39 -06:00
parent 6fff8e3921
commit ac90cd0378
6 changed files with 20 additions and 1 deletions

View file

@ -227,6 +227,7 @@ void EmuWindow_SDL2::Present() {
while (IsOpen()) { while (IsOpen()) {
VideoCore::g_renderer->Present(); VideoCore::g_renderer->Present();
SDL_GL_SwapWindow(render_window); SDL_GL_SwapWindow(render_window);
VideoCore::g_renderer->PresentComplete();
} }
SDL_GL_MakeCurrent(render_window, nullptr); SDL_GL_MakeCurrent(render_window, nullptr);
} }

View file

@ -86,7 +86,7 @@ GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread)
setWindowTitle(QStringLiteral("Citra %1 | %2-%3") setWindowTitle(QStringLiteral("Citra %1 | %2-%3")
.arg(Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc)); .arg(Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc));
setAttribute(Qt::WA_AcceptTouchEvents); setAttribute(Qt::WA_AcceptTouchEvents);
connect(this, &QOpenGLWidget::frameSwapped, this, &GRenderWindow::OnFrameSwapped);
InputCommon::Init(); InputCommon::Init();
} }
@ -104,6 +104,10 @@ void GRenderWindow::DoneCurrent() {
void GRenderWindow::PollEvents() {} void GRenderWindow::PollEvents() {}
void OnFrameSwapped() {
VideoCore::g_renderer->PresentComplete();
}
// On Qt 5.0+, this correctly gets the size of the framebuffer (pixels). // On Qt 5.0+, this correctly gets the size of the framebuffer (pixels).
// //
// Older versions get the window size (density independent pixels), // Older versions get the window size (density independent pixels),
@ -294,6 +298,10 @@ void GRenderWindow::paintGL() {
update(); update();
} }
void GRenderWindow::OnFrameSwapped() {
VideoCore::g_renderer->PresentComplete();
}
void GRenderWindow::showEvent(QShowEvent* event) { void GRenderWindow::showEvent(QShowEvent* event) {
QWidget::showEvent(event); QWidget::showEvent(event);
} }

View file

@ -163,6 +163,7 @@ public slots:
void OnEmulationStarting(EmuThread* emu_thread); void OnEmulationStarting(EmuThread* emu_thread);
void OnEmulationStopping(); void OnEmulationStopping();
void OnFramebufferSizeChanged(); void OnFramebufferSizeChanged();
void OnFrameSwapped();
signals: signals:
/// Emitted when the window is closed /// Emitted when the window is closed

View file

@ -34,6 +34,9 @@ public:
/// Draws the latest frame to the window (Renderer specific implementation) /// Draws the latest frame to the window (Renderer specific implementation)
virtual void Present() = 0; virtual void Present() = 0;
/// Marks the presentation buffer as complete and swaps it back into the pool
virtual void PresentComplete() = 0;
/// Prepares for video dumping (e.g. create necessary buffers, etc) /// Prepares for video dumping (e.g. create necessary buffers, etc)
virtual void PrepareVideoDumping() = 0; virtual void PrepareVideoDumping() = 0;

View file

@ -794,6 +794,9 @@ void RendererOpenGL::Present() {
/* insert fence for the main thread to block on */ /* insert fence for the main thread to block on */
frame.present_sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); frame.present_sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
glFlush(); glFlush();
}
void RendererOpenGL::PresentComplete() {
render_window.mailbox->PresentationComplete(); render_window.mailbox->PresentationComplete();
} }

View file

@ -60,6 +60,9 @@ public:
/// context /// context
void Present() override; void Present() override;
/// Finializes the presentation and sets up the presentation frame to go back into the mailbox
void PresentComplete() override;
/// Prepares for video dumping (e.g. create necessary buffers, etc) /// Prepares for video dumping (e.g. create necessary buffers, etc)
void PrepareVideoDumping() override; void PrepareVideoDumping() override;