Skip to content

Commit

Permalink
Revert "(Vulkan) Add adaptive vsync support (#14788)"
Browse files Browse the repository at this point in the history
This reverts commit 4543a52.
  • Loading branch information
LibretroAdmin committed Feb 21, 2023
1 parent 4543a52 commit e0a0413
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 104 deletions.
101 changes: 30 additions & 71 deletions gfx/common/vulkan_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,7 @@ struct vk_texture vulkan_create_texture(vk_t *vk,

if ((format_properties.linearTilingFeatures & required) != required)
{
#ifdef VULKAN_DEBUG
RARCH_DBG("[Vulkan]: GPU does not support using linear images as textures. Falling back to copy path.\n");
#endif
RARCH_LOG("[Vulkan]: GPU does not support using linear images as textures. Falling back to copy path.\n");
type = VULKAN_TEXTURE_STAGING;
}
}
Expand Down Expand Up @@ -586,7 +584,7 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
{
/* Recreate texture but for STAGING this time ... */
#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
type = VULKAN_TEXTURE_STAGING;
vkDestroyImage(device, tex.image, NULL);
Expand Down Expand Up @@ -2301,7 +2299,7 @@ bool vulkan_surface_create(gfx_ctx_vulkan_data_t *vk,
enum vulkan_wsi_type type,
void *display, void *surface,
unsigned width, unsigned height,
int8_t swap_interval)
unsigned swap_interval)
{
switch (type)
{
Expand Down Expand Up @@ -2930,7 +2928,7 @@ void vulkan_acquire_next_image(gfx_ctx_vulkan_data_t *vk)

bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
unsigned width, unsigned height,
int8_t swap_interval)
unsigned swap_interval)
{
unsigned i;
uint32_t format_count;
Expand Down Expand Up @@ -2980,7 +2978,7 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
{
/* Do not bother creating a swapchain redundantly. */
#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
vulkan_create_wait_fences(vk);

Expand Down Expand Up @@ -3027,12 +3025,6 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,

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;
vkGetPhysicalDeviceSurfacePresentModesKHR(
vk->context.gpu, vk->vk_surface,
Expand All @@ -3046,80 +3038,40 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
vk->context.gpu, vk->vk_surface,
&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++)
{
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];
}
RARCH_LOG("[Vulkan]: Swapchain supports present mode: %u.\n",
present_modes[i]);
}
#endif

vk->context.swap_interval = swap_interval;
for (i = 0; i < present_mode_count; i++)
{
/* Special fallthrough default for mailbox for rather getting it
* 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))
)
if (!swap_interval && present_modes[i] == 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;
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. */
swapchain_present_mode = VK_PRESENT_MODE_FIFO_KHR;
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)
{
case VK_PRESENT_MODE_IMMEDIATE_KHR:
RARCH_DBG("[Vulkan]: Creating swapchain with present mode: IMMEDIATE_KHR.\n");
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;
}
#ifdef VULKAN_DEBUG
RARCH_LOG("[Vulkan]: Creating swapchain with present mode: %u\n",
(unsigned)swapchain_present_mode);
#endif

vkGetPhysicalDeviceSurfaceFormatsKHR(vk->context.gpu,
vk->vk_surface, &format_count, NULL);
Expand Down Expand Up @@ -3220,13 +3172,20 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
vk->context.num_swapchain_images = 1;

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;
}

if (vk->swapchain == VK_NULL_HANDLE)
RARCH_DBG("[Vulkan]: Using swapchain size %ux%u.\n",
swapchain_size.width, swapchain_size.height);
#ifdef VULKAN_DEBUG
RARCH_LOG("[Vulkan]: Using swapchain size %ux%u.\n",
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. */
if (desired_swapchain_images < surface_properties.minImageCount)
Expand Down
7 changes: 3 additions & 4 deletions gfx/common/vulkan_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ typedef struct vulkan_context
VkPhysicalDeviceProperties gpu_properties;
VkPhysicalDeviceMemoryProperties memory_properties;

VkPresentModeKHR present_modes[16];
VkImage swapchain_images[VULKAN_MAX_SWAPCHAIN_IMAGES];
VkFence swapchain_fences[VULKAN_MAX_SWAPCHAIN_IMAGES];
VkFormat swapchain_format;
Expand All @@ -157,9 +156,9 @@ typedef struct vulkan_context

unsigned swapchain_width;
unsigned swapchain_height;
unsigned swap_interval;
unsigned num_recycled_acquire_semaphores;

int8_t swap_interval;
uint8_t flags;

bool swapchain_fences_signalled[VULKAN_MAX_SWAPCHAIN_IMAGES];
Expand Down Expand Up @@ -725,15 +724,15 @@ bool vulkan_surface_create(gfx_ctx_vulkan_data_t *vk,
enum vulkan_wsi_type type,
void *display, void *surface,
unsigned width, unsigned height,
int8_t swap_interval);
unsigned swap_interval);

void vulkan_present(gfx_ctx_vulkan_data_t *vk, unsigned index);

void vulkan_acquire_next_image(gfx_ctx_vulkan_data_t *vk);

bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
unsigned width, unsigned height,
int8_t swap_interval);
unsigned swap_interval);

void vulkan_set_uniform_buffer(
VkDevice device,
Expand Down
16 changes: 1 addition & 15 deletions gfx/drivers_context/w_vk_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
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;
}
}

uint32_t flags = 0;
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif

return flags;
}

Expand Down
16 changes: 2 additions & 14 deletions gfx/drivers_context/x_vk_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
gfx_ctx_x_vk_data_t *x = (gfx_ctx_x_vk_data_t*)data;
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 (x->vk.context.present_modes[i] == VK_PRESENT_MODE_FIFO_RELAXED_KHR)
{
BIT32_SET(flags, GFX_CTX_FLAGS_ADAPTIVE_VSYNC);
break;
}
}
uint32_t flags = 0;
gfx_ctx_x_vk_data_t *x = (gfx_ctx_x_vk_data_t*)data;

#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
Expand Down

0 comments on commit e0a0413

Please sign in to comment.