Revert "(Vulkan) Add adaptive vsync support (#14788)" (#15004)

This reverts commit 4543a52be67f172b825bb284d75d03924f5ed8a9.
This commit is contained in:
LibretroAdmin 2023-02-21 23:00:06 +01:00 committed by GitHub
parent 4543a52be6
commit c810520a55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 104 deletions

View File

@ -482,9 +482,7 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
if ((format_properties.linearTilingFeatures & required) != required) if ((format_properties.linearTilingFeatures & required) != required)
{ {
#ifdef VULKAN_DEBUG RARCH_LOG("[Vulkan]: GPU does not support using linear images as textures. Falling back to copy path.\n");
RARCH_DBG("[Vulkan]: GPU does not support using linear images as textures. Falling back to copy path.\n");
#endif
type = VULKAN_TEXTURE_STAGING; type = VULKAN_TEXTURE_STAGING;
} }
} }
@ -586,7 +584,7 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
{ {
/* Recreate texture but for STAGING this time ... */ /* Recreate texture but for STAGING this time ... */
#ifdef VULKAN_DEBUG #ifdef VULKAN_DEBUG
RARCH_DBG("[Vulkan]: GPU supports linear images as textures, but not DEVICE_LOCAL. Falling back to copy path.\n"); RARCH_LOG("[Vulkan]: GPU supports linear images as textures, but not DEVICE_LOCAL. Falling back to copy path.\n");
#endif #endif
type = VULKAN_TEXTURE_STAGING; type = VULKAN_TEXTURE_STAGING;
vkDestroyImage(device, tex.image, NULL); vkDestroyImage(device, tex.image, NULL);
@ -2301,7 +2299,7 @@ bool vulkan_surface_create(gfx_ctx_vulkan_data_t *vk,
enum vulkan_wsi_type type, enum vulkan_wsi_type type,
void *display, void *surface, void *display, void *surface,
unsigned width, unsigned height, unsigned width, unsigned height,
int8_t swap_interval) unsigned swap_interval)
{ {
switch (type) switch (type)
{ {
@ -2930,7 +2928,7 @@ retry:
bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk, bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
unsigned width, unsigned height, unsigned width, unsigned height,
int8_t swap_interval) unsigned swap_interval)
{ {
unsigned i; unsigned i;
uint32_t format_count; uint32_t format_count;
@ -2980,7 +2978,7 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
{ {
/* Do not bother creating a swapchain redundantly. */ /* Do not bother creating a swapchain redundantly. */
#ifdef VULKAN_DEBUG #ifdef VULKAN_DEBUG
RARCH_DBG("[Vulkan]: Do not need to re-create swapchain.\n"); RARCH_LOG("[Vulkan]: Do not need to re-create swapchain.\n");
#endif #endif
vulkan_create_wait_fences(vk); vulkan_create_wait_fences(vk);
@ -3027,12 +3025,6 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
vulkan_emulated_mailbox_deinit(&vk->mailbox); vulkan_emulated_mailbox_deinit(&vk->mailbox);
/* Unless we have other reasons to clamp, we should prefer 3 images.
* We hard sync against the swapchain, so if we have 2 images,
* we would be unable to overlap CPU and GPU, which can get very slow
* for GPU-rendered cores. */
desired_swapchain_images = settings->uints.video_max_swapchain_images;
present_mode_count = 0; present_mode_count = 0;
vkGetPhysicalDeviceSurfacePresentModesKHR( vkGetPhysicalDeviceSurfacePresentModesKHR(
vk->context.gpu, vk->vk_surface, vk->context.gpu, vk->vk_surface,
@ -3046,80 +3038,40 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
vk->context.gpu, vk->vk_surface, vk->context.gpu, vk->vk_surface,
&present_mode_count, present_modes); &present_mode_count, present_modes);
if (vk->swapchain == VK_NULL_HANDLE) #ifdef VULKAN_DEBUG
for (i = 0; i < present_mode_count; i++)
{ {
for (i = 0; i < present_mode_count; i++) RARCH_LOG("[Vulkan]: Swapchain supports present mode: %u.\n",
{ present_modes[i]);
switch (present_modes[i])
{
case VK_PRESENT_MODE_IMMEDIATE_KHR:
RARCH_DBG("[Vulkan]: Swapchain supports present mode: IMMEDIATE_KHR.\n");
break;
case VK_PRESENT_MODE_MAILBOX_KHR:
RARCH_DBG("[Vulkan]: Swapchain supports present mode: MAILBOX_KHR.\n");
break;
case VK_PRESENT_MODE_FIFO_KHR:
RARCH_DBG("[Vulkan]: Swapchain supports present mode: FIFO_KHR.\n");
break;
case VK_PRESENT_MODE_FIFO_RELAXED_KHR:
RARCH_DBG("[Vulkan]: Swapchain supports present mode: FIFO_RELAXED_KHR.\n");
break;
default:
break;
}
vk->context.present_modes[i] = present_modes[i];
}
} }
#endif
vk->context.swap_interval = swap_interval; vk->context.swap_interval = swap_interval;
for (i = 0; i < present_mode_count; i++) for (i = 0; i < present_mode_count; i++)
{ {
/* Special fallthrough default for mailbox for rather getting it if (!swap_interval && present_modes[i] == VK_PRESENT_MODE_MAILBOX_KHR)
* than fifo without vsync when immediate is not available */
if (present_modes[i] == VK_PRESENT_MODE_MAILBOX_KHR
&& ( (swap_interval > 0 && desired_swapchain_images > 2)
|| (swap_interval < 1 && swapchain_present_mode == VK_PRESENT_MODE_FIFO_KHR))
)
{ {
swapchain_present_mode = VK_PRESENT_MODE_MAILBOX_KHR; swapchain_present_mode = VK_PRESENT_MODE_MAILBOX_KHR;
continue; break;
} }
else if (swap_interval == 0 && present_modes[i] == VK_PRESENT_MODE_IMMEDIATE_KHR) else if (!swap_interval && present_modes[i]
== VK_PRESENT_MODE_IMMEDIATE_KHR)
{ {
swapchain_present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR; swapchain_present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR;
break; break;
} }
else if (swap_interval > 0 && present_modes[i] == VK_PRESENT_MODE_FIFO_KHR) else if (swap_interval && present_modes[i] == VK_PRESENT_MODE_FIFO_KHR)
{ {
/* Kind of tautological since FIFO must always be present. */ /* Kind of tautological since FIFO must always be present. */
swapchain_present_mode = VK_PRESENT_MODE_FIFO_KHR; swapchain_present_mode = VK_PRESENT_MODE_FIFO_KHR;
break; break;
} }
else if (swap_interval < 0 && present_modes[i] == VK_PRESENT_MODE_FIFO_RELAXED_KHR)
{
swapchain_present_mode = VK_PRESENT_MODE_FIFO_RELAXED_KHR;
break;
}
} }
switch (swapchain_present_mode) #ifdef VULKAN_DEBUG
{ RARCH_LOG("[Vulkan]: Creating swapchain with present mode: %u\n",
case VK_PRESENT_MODE_IMMEDIATE_KHR: (unsigned)swapchain_present_mode);
RARCH_DBG("[Vulkan]: Creating swapchain with present mode: IMMEDIATE_KHR.\n"); #endif
break;
case VK_PRESENT_MODE_MAILBOX_KHR:
RARCH_DBG("[Vulkan]: Creating swapchain with present mode: MAILBOX_KHR.\n");
break;
case VK_PRESENT_MODE_FIFO_KHR:
RARCH_DBG("[Vulkan]: Creating swapchain with present mode: FIFO_KHR.\n");
break;
case VK_PRESENT_MODE_FIFO_RELAXED_KHR:
RARCH_DBG("[Vulkan]: Creating swapchain with present mode: FIFO_RELAXED_KHR.\n");
break;
default:
break;
}
vkGetPhysicalDeviceSurfaceFormatsKHR(vk->context.gpu, vkGetPhysicalDeviceSurfaceFormatsKHR(vk->context.gpu,
vk->vk_surface, &format_count, NULL); vk->vk_surface, &format_count, NULL);
@ -3220,13 +3172,20 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
vk->context.num_swapchain_images = 1; vk->context.num_swapchain_images = 1;
memset(vk->context.swapchain_images, 0, sizeof(vk->context.swapchain_images)); memset(vk->context.swapchain_images, 0, sizeof(vk->context.swapchain_images));
RARCH_DBG("[Vulkan]: Cannot create a swapchain yet. Will try again later..\n"); RARCH_LOG("[Vulkan]: Cannot create a swapchain yet. Will try again later ...\n");
return true; return true;
} }
if (vk->swapchain == VK_NULL_HANDLE) #ifdef VULKAN_DEBUG
RARCH_DBG("[Vulkan]: Using swapchain size %ux%u.\n", RARCH_LOG("[Vulkan]: Using swapchain size %ux%u.\n",
swapchain_size.width, swapchain_size.height); swapchain_size.width, swapchain_size.height);
#endif
/* Unless we have other reasons to clamp, we should prefer 3 images.
* We hard sync against the swapchain, so if we have 2 images,
* we would be unable to overlap CPU and GPU, which can get very slow
* for GPU-rendered cores. */
desired_swapchain_images = settings->uints.video_max_swapchain_images;
/* Clamp images requested to what is supported by the implementation. */ /* Clamp images requested to what is supported by the implementation. */
if (desired_swapchain_images < surface_properties.minImageCount) if (desired_swapchain_images < surface_properties.minImageCount)

View File

@ -134,7 +134,6 @@ typedef struct vulkan_context
VkPhysicalDeviceProperties gpu_properties; VkPhysicalDeviceProperties gpu_properties;
VkPhysicalDeviceMemoryProperties memory_properties; VkPhysicalDeviceMemoryProperties memory_properties;
VkPresentModeKHR present_modes[16];
VkImage swapchain_images[VULKAN_MAX_SWAPCHAIN_IMAGES]; VkImage swapchain_images[VULKAN_MAX_SWAPCHAIN_IMAGES];
VkFence swapchain_fences[VULKAN_MAX_SWAPCHAIN_IMAGES]; VkFence swapchain_fences[VULKAN_MAX_SWAPCHAIN_IMAGES];
VkFormat swapchain_format; VkFormat swapchain_format;
@ -157,9 +156,9 @@ typedef struct vulkan_context
unsigned swapchain_width; unsigned swapchain_width;
unsigned swapchain_height; unsigned swapchain_height;
unsigned swap_interval;
unsigned num_recycled_acquire_semaphores; unsigned num_recycled_acquire_semaphores;
int8_t swap_interval;
uint8_t flags; uint8_t flags;
bool swapchain_fences_signalled[VULKAN_MAX_SWAPCHAIN_IMAGES]; bool swapchain_fences_signalled[VULKAN_MAX_SWAPCHAIN_IMAGES];
@ -725,7 +724,7 @@ bool vulkan_surface_create(gfx_ctx_vulkan_data_t *vk,
enum vulkan_wsi_type type, enum vulkan_wsi_type type,
void *display, void *surface, void *display, void *surface,
unsigned width, unsigned height, unsigned width, unsigned height,
int8_t swap_interval); unsigned swap_interval);
void vulkan_present(gfx_ctx_vulkan_data_t *vk, unsigned index); void vulkan_present(gfx_ctx_vulkan_data_t *vk, unsigned index);
@ -733,7 +732,7 @@ void vulkan_acquire_next_image(gfx_ctx_vulkan_data_t *vk);
bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk, bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
unsigned width, unsigned height, unsigned width, unsigned height,
int8_t swap_interval); unsigned swap_interval);
void vulkan_set_uniform_buffer( void vulkan_set_uniform_buffer(
VkDevice device, VkDevice device,

View File

@ -330,24 +330,10 @@ static void *gfx_ctx_w_vk_get_context_data(void *data) { return &win32_vk.contex
static uint32_t gfx_ctx_w_vk_get_flags(void *data) static uint32_t gfx_ctx_w_vk_get_flags(void *data)
{ {
uint32_t flags = 0; uint32_t flags = 0;
uint8_t present_mode_count = 16;
uint8_t i = 0;
/* Check for FIFO_RELAXED_KHR capability */
for (i = 0; i < present_mode_count; i++)
{
if (win32_vk.context.present_modes[i] == VK_PRESENT_MODE_FIFO_RELAXED_KHR)
{
BIT32_SET(flags, GFX_CTX_FLAGS_ADAPTIVE_VSYNC);
break;
}
}
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS) #if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG); BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif #endif
return flags; return flags;
} }

View File

@ -541,20 +541,8 @@ static void *gfx_ctx_x_vk_get_context_data(void *data)
static uint32_t gfx_ctx_x_vk_get_flags(void *data) static uint32_t gfx_ctx_x_vk_get_flags(void *data)
{ {
gfx_ctx_x_vk_data_t *x = (gfx_ctx_x_vk_data_t*)data; uint32_t flags = 0;
uint32_t flags = 0; gfx_ctx_x_vk_data_t *x = (gfx_ctx_x_vk_data_t*)data;
uint8_t present_mode_count = 16;
uint8_t i = 0;
/* Check for FIFO_RELAXED_KHR capability */
for (i = 0; i < present_mode_count; i++)
{
if (x->vk.context.present_modes[i] == VK_PRESENT_MODE_FIFO_RELAXED_KHR)
{
BIT32_SET(flags, GFX_CTX_FLAGS_ADAPTIVE_VSYNC);
break;
}
}
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS) #if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG); BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);