Optimize call to vulkan_present

This commit is contained in:
twinaphex 2020-07-20 04:45:12 +02:00
parent 0e9a86816e
commit 9ac9309991
7 changed files with 62 additions and 21 deletions

View File

@ -2561,19 +2561,8 @@ static void vulkan_destroy_swapchain(gfx_ctx_vulkan_data_t *vk)
void vulkan_present(gfx_ctx_vulkan_data_t *vk, unsigned index)
{
VkPresentInfoKHR present;
VkResult result = VK_SUCCESS;
VkResult err = VK_SUCCESS;
if (!vk->context.has_acquired_swapchain)
return;
vk->context.has_acquired_swapchain = false;
/* We're still waiting for a proper swapchain, so just fake it. */
if (vk->swapchain == VK_NULL_HANDLE)
{
retro_sleep(10);
return;
}
VkResult result = VK_SUCCESS;
VkResult err = VK_SUCCESS;
present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
present.pNext = NULL;
@ -2590,8 +2579,10 @@ void vulkan_present(gfx_ctx_vulkan_data_t *vk, unsigned index)
#endif
err = vkQueuePresentKHR(vk->context.queue, &present);
/* VK_SUBOPTIMAL_KHR can be returned on Android 10 when prerotate is not dealt with.
* This is not an error we need to care about, and we'll treat it as SUCCESS. */
/* VK_SUBOPTIMAL_KHR can be returned on
* Android 10 when prerotate is not dealt with.
* This is not an error we need to care about,
* and we'll treat it as SUCCESS. */
if (result == VK_SUBOPTIMAL_KHR)
result = VK_SUCCESS;
if (err == VK_SUBOPTIMAL_KHR)

View File

@ -20,6 +20,7 @@
#include <formats/image.h>
#include <string/stdstring.h>
#include <compat/strl.h>
#include <retro_timers.h>
#ifdef HAVE_CONFIG_H
#include "../../config.h"
@ -257,7 +258,14 @@ static void android_gfx_ctx_vk_swap_buffers(void *data)
{
android_ctx_data_vk_t *and = (android_ctx_data_vk_t*)data;
vulkan_present(&and->vk, and->vk.context.current_swapchain_index);
if (and->vk.context.has_acquired_swapchain)
{
and->vk.context.has_acquired_swapchain = false;
if (and->vk.swapchain == VK_NULL_HANDLE)
retro_sleep(10);
else
vulkan_present(&and->vk, and->vk.context.current_swapchain_index);
}
vulkan_acquire_next_image(&and->vk);
}

View File

@ -33,6 +33,7 @@
#endif
#include <retro_assert.h>
#include <retro_timers.h>
#include <compat/apple_compat.h>
#include <string/stdstring.h>
@ -641,7 +642,14 @@ static void cocoagl_gfx_ctx_swap_buffers(void *data)
break;
case GFX_CTX_VULKAN_API:
#ifdef HAVE_VULKAN
vulkan_present(&cocoa_ctx->vk, cocoa_ctx->vk.context.current_swapchain_index);
if (cocoa_ctx->vk.context.has_acquired_swapchain)
{
cocoa_ctx->vk.context.has_acquired_swapchain = false;
if (cocoa_ctx->vk.swapchain == VK_NULL_HANDLE)
retro_sleep(10);
else
vulkan_present(&cocoa_ctx->vk, cocoa_ctx->vk.context.current_swapchain_index);
}
vulkan_acquire_next_image(&cocoa_ctx->vk);
#endif
break;

View File

@ -15,6 +15,7 @@
#include <compat/strl.h>
#include <string/stdstring.h>
#include <retro_timers.h>
#ifdef HAVE_CONFIG_H
#include "../../config.h"
@ -230,7 +231,14 @@ static void gfx_ctx_khr_display_set_swap_interval(void *data,
static void gfx_ctx_khr_display_swap_buffers(void *data)
{
khr_display_ctx_data_t *khr = (khr_display_ctx_data_t*)data;
vulkan_present(&khr->vk, khr->vk.context.current_swapchain_index);
if (khr->vk.context.has_acquired_swapchain)
{
khr->vk.context.has_acquired_swapchain = false;
if (khr->vk.swapchain == VK_NULL_HANDLE)
retro_sleep(10);
else
vulkan_present(&khr->vk, khr->vk.context.current_swapchain_index);
}
vulkan_acquire_next_image(&khr->vk);
}

View File

@ -34,6 +34,7 @@
#include <dynamic/dylib.h>
#include <string/stdstring.h>
#include <retro_timers.h>
#ifdef HAVE_CONFIG_H
#include "../../config.h"
@ -101,7 +102,15 @@ static void gfx_ctx_w_vk_check_window(void *data, bool *quit,
static void gfx_ctx_w_vk_swap_buffers(void *data)
{
vulkan_present(&win32_vk, win32_vk.context.current_swapchain_index);
if (win32_vk.context.has_acquired_swapchain)
{
win32_vk.context.has_acquired_swapchain = false;
/* We're still waiting for a proper swapchain, so just fake it. */
if (win32_vk.swapchain == VK_NULL_HANDLE)
retro_sleep(10);
else
vulkan_present(&win32_vk, win32_vk.context.current_swapchain_index);
}
vulkan_acquire_next_image(&win32_vk);
}

View File

@ -45,6 +45,8 @@
/* Generated from xdg-decoration-unstable-v1.h */
#include "../common/wayland/xdg-decoration-unstable-v1.h"
#include <retro_timers.h>
#ifndef EGL_PLATFORM_WAYLAND_KHR
#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
#endif
@ -609,7 +611,14 @@ static void gfx_ctx_wl_swap_buffers(void *data)
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
vulkan_present(&wl->vk, wl->vk.context.current_swapchain_index);
if (wl->vk.context.has_acquired_swapchain)
{
wl->vk.context.has_acquired_swapchain = false;
if (wl->vk.swapchain == VK_NULL_HANDLE)
retro_sleep(10);
else
vulkan_present(&wl->vk, wl->vk.context.current_swapchain_index);
}
vulkan_acquire_next_image(&wl->vk);
flush_wayland_fd(&wl->input);
}

View File

@ -25,6 +25,7 @@
#include <string/stdstring.h>
#include <compat/strcasestr.h>
#include <retro_timers.h>
#include <X11/Xatom.h>
#include "../../configuration.h"
@ -150,7 +151,14 @@ static void gfx_ctx_x_vk_swap_buffers(void *data)
{
gfx_ctx_x_vk_data_t *x = (gfx_ctx_x_vk_data_t*)data;
vulkan_present(&x->vk, x->vk.context.current_swapchain_index);
if (x->vk.context.has_acquired_swapchain)
{
x->vk.context.has_acquired_swapchain = false;
if (x->vk.swapchain == VK_NULL_HANDLE)
retro_sleep(10);
else
vulkan_present(&x->vk, x->vk.context.current_swapchain_index);
}
vulkan_acquire_next_image(&x->vk);
}