mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 21:32:45 +00:00
gfx_ctx_vulkan_data - use flags instead of booleans
This commit is contained in:
parent
250a0b9542
commit
0159c2f70f
@ -1636,21 +1636,24 @@ static bool vulkan_context_init_device(gfx_ctx_vulkan_data_t *vk)
|
||||
#ifdef VULKAN_EMULATE_MAILBOX
|
||||
/* Win32 windowed mode seems to deal just fine with toggling VSync.
|
||||
* Fullscreen however ... */
|
||||
vk->emulate_mailbox = vk->fullscreen;
|
||||
if (vk->flags & VK_DATA_FLAG_FULLSCREEN)
|
||||
vk->flags |= VK_DATA_FLAG_EMULATE_MAILBOX;
|
||||
else
|
||||
vk->flags &= ~VK_DATA_FLAG_EMULATE_MAILBOX;
|
||||
#endif
|
||||
|
||||
/* If we're emulating mailbox, stick to using fences rather than semaphores.
|
||||
* Avoids some really weird driver bugs. */
|
||||
if (!vk->emulate_mailbox)
|
||||
if (!(vk->flags & VK_DATA_FLAG_EMULATE_MAILBOX))
|
||||
{
|
||||
if (vk->context.gpu_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
|
||||
{
|
||||
vk->use_wsi_semaphore = true;
|
||||
vk->flags |= VK_DATA_FLAG_USE_WSI_SEMAPHORE;
|
||||
RARCH_LOG("[Vulkan]: Using semaphores for WSI acquire.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
vk->use_wsi_semaphore = false;
|
||||
vk->flags &= ~VK_DATA_FLAG_USE_WSI_SEMAPHORE;
|
||||
RARCH_LOG("[Vulkan]: Using fences for WSI acquire.\n");
|
||||
}
|
||||
}
|
||||
@ -2733,7 +2736,7 @@ retry:
|
||||
|
||||
retro_assert(!vk->context.has_acquired_swapchain);
|
||||
|
||||
if (vk->emulating_mailbox)
|
||||
if (vk->flags & VK_DATA_FLAG_EMULATING_MAILBOX)
|
||||
{
|
||||
/* Non-blocking acquire. If we don't get a swapchain frame right away,
|
||||
* just skip rendering to the swapchain this frame, similar to what
|
||||
@ -2746,7 +2749,7 @@ retry:
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vk->use_wsi_semaphore)
|
||||
if (vk->flags & VK_DATA_FLAG_USE_WSI_SEMAPHORE)
|
||||
semaphore = vulkan_get_wsi_acquire_semaphore(&vk->context);
|
||||
else
|
||||
vkCreateFence(vk->context.device, &fence_info, NULL, &fence);
|
||||
@ -2877,15 +2880,17 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
|
||||
!surface_properties.currentExtent.height)
|
||||
return false;
|
||||
|
||||
if (swap_interval == 0 && vk->emulate_mailbox && vsync)
|
||||
if ( (swap_interval == 0)
|
||||
&& (vk->flags & VK_DATA_FLAG_EMULATE_MAILBOX)
|
||||
&& vsync)
|
||||
{
|
||||
swap_interval = 1;
|
||||
vk->emulating_mailbox = true;
|
||||
swap_interval = 1;
|
||||
vk->flags |= VK_DATA_FLAG_EMULATING_MAILBOX;
|
||||
}
|
||||
else
|
||||
vk->emulating_mailbox = false;
|
||||
vk->flags &= ~VK_DATA_FLAG_EMULATING_MAILBOX;
|
||||
|
||||
vk->created_new_swapchain = true;
|
||||
vk->flags |= VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN;
|
||||
|
||||
if (vk->swapchain != VK_NULL_HANDLE &&
|
||||
!vk->context.invalid_swapchain &&
|
||||
@ -2899,17 +2904,17 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
|
||||
#endif
|
||||
vulkan_create_wait_fences(vk);
|
||||
|
||||
if ( vk->emulating_mailbox
|
||||
if ( (vk->flags & VK_DATA_FLAG_EMULATING_MAILBOX)
|
||||
&& vk->mailbox.swapchain == VK_NULL_HANDLE)
|
||||
{
|
||||
vulkan_emulated_mailbox_init(
|
||||
&vk->mailbox, vk->context.device, vk->swapchain);
|
||||
vk->created_new_swapchain = false;
|
||||
vk->flags &= ~VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN;
|
||||
return true;
|
||||
}
|
||||
else if (
|
||||
!vk->emulating_mailbox
|
||||
&& vk->mailbox.swapchain != VK_NULL_HANDLE)
|
||||
(!(vk->flags & VK_DATA_FLAG_EMULATING_MAILBOX))
|
||||
&& (vk->mailbox.swapchain != VK_NULL_HANDLE))
|
||||
{
|
||||
VkResult res = VK_SUCCESS;
|
||||
/* We are tearing down, and entering a state
|
||||
@ -2926,7 +2931,7 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
|
||||
if (res == VK_SUCCESS)
|
||||
{
|
||||
vk->context.has_acquired_swapchain = true;
|
||||
vk->created_new_swapchain = false;
|
||||
vk->flags &= ~VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2935,7 +2940,7 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
|
||||
}
|
||||
else
|
||||
{
|
||||
vk->created_new_swapchain = false;
|
||||
vk->flags &= ~VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -3212,7 +3217,7 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
|
||||
vk->context.has_acquired_swapchain = false;
|
||||
vulkan_create_wait_fences(vk);
|
||||
|
||||
if (vk->emulating_mailbox)
|
||||
if (vk->flags & VK_DATA_FLAG_EMULATING_MAILBOX)
|
||||
vulkan_emulated_mailbox_init(&vk->mailbox, vk->context.device, vk->swapchain);
|
||||
|
||||
return true;
|
||||
|
@ -186,28 +186,29 @@ struct vulkan_emulated_mailbox
|
||||
uint8_t flags;
|
||||
};
|
||||
|
||||
typedef struct gfx_ctx_vulkan_data
|
||||
enum gfx_ctx_vulkan_data_flags
|
||||
{
|
||||
struct string_list *gpu_list;
|
||||
|
||||
vulkan_context_t context;
|
||||
VkSurfaceKHR vk_surface; /* ptr alignment */
|
||||
VkSwapchainKHR swapchain; /* ptr alignment */
|
||||
|
||||
struct vulkan_emulated_mailbox mailbox;
|
||||
|
||||
/* Used to check if we need to use mailbox emulation or not.
|
||||
* Only relevant on Windows for now. */
|
||||
bool fullscreen;
|
||||
|
||||
bool need_new_swapchain;
|
||||
bool created_new_swapchain;
|
||||
bool emulate_mailbox;
|
||||
bool emulating_mailbox;
|
||||
/* If set, prefer a path where we use
|
||||
* semaphores instead of fences for vkAcquireNextImageKHR.
|
||||
* Helps workaround certain performance issues on some drivers. */
|
||||
bool use_wsi_semaphore;
|
||||
VK_DATA_FLAG_USE_WSI_SEMAPHORE = (1 << 0),
|
||||
VK_DATA_FLAG_NEED_NEW_SWAPCHAIN = (1 << 1),
|
||||
VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN = (1 << 2),
|
||||
VK_DATA_FLAG_EMULATE_MAILBOX = (1 << 3),
|
||||
VK_DATA_FLAG_EMULATING_MAILBOX = (1 << 4),
|
||||
/* Used to check if we need to use mailbox emulation or not.
|
||||
* Only relevant on Windows for now. */
|
||||
VK_DATA_FLAG_FULLSCREEN = (1 << 5)
|
||||
};
|
||||
|
||||
typedef struct gfx_ctx_vulkan_data
|
||||
{
|
||||
struct string_list *gpu_list;
|
||||
vulkan_context_t context;
|
||||
VkSurfaceKHR vk_surface; /* ptr alignment */
|
||||
VkSwapchainKHR swapchain; /* ptr alignment */
|
||||
struct vulkan_emulated_mailbox mailbox;
|
||||
uint8_t flags;
|
||||
} gfx_ctx_vulkan_data_t;
|
||||
|
||||
struct vulkan_display_surface_info
|
||||
|
@ -107,13 +107,13 @@ static void android_gfx_ctx_vk_check_window(void *data, bool *quit,
|
||||
|
||||
if (android_app->content_rect.changed)
|
||||
{
|
||||
and->vk.need_new_swapchain = true;
|
||||
and->vk.flags |= VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
android_app->content_rect.changed = false;
|
||||
}
|
||||
|
||||
/* Swapchains are recreated in set_resize as a
|
||||
* central place, so use that to trigger swapchain reinit. */
|
||||
*resize = and->vk.need_new_swapchain;
|
||||
*resize = and->vk.flags & VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
new_width = android_app->content_rect.width;
|
||||
new_height = android_app->content_rect.height;
|
||||
|
||||
@ -143,10 +143,10 @@ static bool android_gfx_ctx_vk_set_resize(void *data,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (and->vk.created_new_swapchain)
|
||||
if (and->vk.flags & VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN)
|
||||
vulkan_acquire_next_image(&and->vk);
|
||||
and->vk.context.invalid_swapchain = true;
|
||||
and->vk.need_new_swapchain = false;
|
||||
and->vk.flags &= ~VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -276,7 +276,7 @@ static void android_gfx_ctx_vk_set_swap_interval(void *data, int swap_interval)
|
||||
RARCH_LOG("[Vulkan]: Setting swap interval: %u.\n", swap_interval);
|
||||
and->swap_interval = swap_interval;
|
||||
if (and->vk.swapchain)
|
||||
and->vk.need_new_swapchain = true;
|
||||
and->vk.flags |= VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,8 @@ static void cocoa_vk_gfx_ctx_check_window(void *data, bool *quit,
|
||||
|
||||
*quit = false;
|
||||
|
||||
*resize = cocoa_ctx->vk.need_new_swapchain;
|
||||
*resize = cocoa_ctx->vk.flags &
|
||||
VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
|
||||
#if MAC_OS_X_VERSION_10_7 && defined(OSX)
|
||||
cocoa_vk_gfx_ctx_get_video_size_osx10_7_and_up(data, &new_width, &new_height);
|
||||
@ -169,7 +170,7 @@ static void cocoa_vk_gfx_ctx_swap_interval(void *data, int i)
|
||||
{
|
||||
cocoa_ctx->swap_interval = interval;
|
||||
if (cocoa_ctx->vk.swapchain)
|
||||
cocoa_ctx->vk.need_new_swapchain = true;
|
||||
cocoa_ctx->vk.flags |= VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
}
|
||||
}
|
||||
|
||||
@ -320,10 +321,10 @@ static bool cocoa_vk_gfx_ctx_set_resize(void *data, unsigned width, unsigned hei
|
||||
}
|
||||
|
||||
cocoa_ctx->vk.context.invalid_swapchain = true;
|
||||
if (cocoa_ctx->vk.created_new_swapchain)
|
||||
if (cocoa_ctx->vk.flags & VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN)
|
||||
vulkan_acquire_next_image(&cocoa_ctx->vk);
|
||||
|
||||
cocoa_ctx->vk.need_new_swapchain = false;
|
||||
cocoa_ctx->vk.flags &= ~VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ static void gfx_ctx_khr_display_check_window(void *data, bool *quit,
|
||||
{
|
||||
khr_display_ctx_data_t *khr = (khr_display_ctx_data_t*)data;
|
||||
|
||||
*resize = khr->vk.need_new_swapchain;
|
||||
*resize = khr->vk.flags & VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
|
||||
if (khr->width != *width || khr->height != *height)
|
||||
{
|
||||
@ -112,11 +112,11 @@ static bool gfx_ctx_khr_display_set_resize(void *data,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (khr->vk.created_new_swapchain)
|
||||
if (khr->vk.flags & VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN)
|
||||
vulkan_acquire_next_image(&khr->vk);
|
||||
|
||||
khr->vk.context.invalid_swapchain = true;
|
||||
khr->vk.need_new_swapchain = false;
|
||||
khr->vk.flags &= ~VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -224,7 +224,7 @@ static void gfx_ctx_khr_display_set_swap_interval(void *data,
|
||||
{
|
||||
khr->swap_interval = swap_interval;
|
||||
if (khr->vk.swapchain)
|
||||
khr->vk.need_new_swapchain = true;
|
||||
khr->vk.flags |= VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ static void gfx_ctx_w_vk_swap_interval(void *data, int interval)
|
||||
{
|
||||
win32_vk_interval = interval;
|
||||
if (win32_vk.swapchain)
|
||||
win32_vk.need_new_swapchain = true;
|
||||
win32_vk.flags |= VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ static void gfx_ctx_w_vk_check_window(void *data, bool *quit,
|
||||
|
||||
win32_check_window(NULL, quit, resize, width, height);
|
||||
|
||||
if (win32_vk.need_new_swapchain)
|
||||
if (win32_vk.flags & VK_DATA_FLAG_NEED_NEW_SWAPCHAIN)
|
||||
*resize = true;
|
||||
|
||||
/* Trigger video driver init when changing refresh rate
|
||||
@ -111,11 +111,12 @@ static void gfx_ctx_w_vk_check_window(void *data, bool *quit,
|
||||
* Bigger than zero difference required in order to prevent
|
||||
* constant reinit when adjusting rate option in 0.001 increments.
|
||||
*/
|
||||
if (win32_vk.fullscreen && g_win32_refresh_rate &&
|
||||
g_win32_refresh_rate != refresh_rate &&
|
||||
abs(g_win32_refresh_rate - refresh_rate) > 0 &&
|
||||
g_win32_resize_width == *width &&
|
||||
g_win32_resize_height == *height)
|
||||
if ( (win32_vk.flags & VK_DATA_FLAG_FULLSCREEN)
|
||||
&& (g_win32_refresh_rate)
|
||||
&& (g_win32_refresh_rate != refresh_rate)
|
||||
&& (abs(g_win32_refresh_rate - refresh_rate) > 0)
|
||||
&& (g_win32_resize_width == *width)
|
||||
&& (g_win32_resize_height == *height))
|
||||
{
|
||||
g_win32_refresh_rate = settings->floats.video_refresh_rate;
|
||||
command_event(CMD_EVENT_REINIT, NULL);
|
||||
@ -141,10 +142,10 @@ static bool gfx_ctx_w_vk_set_resize(void *data,
|
||||
{
|
||||
if (vulkan_create_swapchain(&win32_vk, width, height, win32_vk_interval))
|
||||
{
|
||||
if (win32_vk.created_new_swapchain)
|
||||
if (win32_vk.flags & VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN)
|
||||
vulkan_acquire_next_image(&win32_vk);
|
||||
win32_vk.context.invalid_swapchain = true;
|
||||
win32_vk.need_new_swapchain = false;
|
||||
win32_vk.flags &= ~VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -267,7 +268,10 @@ static bool gfx_ctx_w_vk_set_video_mode(void *data,
|
||||
unsigned width, unsigned height,
|
||||
bool fullscreen)
|
||||
{
|
||||
win32_vk.fullscreen = fullscreen;
|
||||
if (fullscreen)
|
||||
win32_vk.flags |= VK_DATA_FLAG_FULLSCREEN;
|
||||
else
|
||||
win32_vk.flags &= ~VK_DATA_FLAG_FULLSCREEN;
|
||||
|
||||
if (win32_set_video_mode(NULL, width, height, fullscreen))
|
||||
{
|
||||
|
@ -82,7 +82,7 @@ static void gfx_ctx_wl_check_window(void *data, bool *quit,
|
||||
|
||||
/* Swapchains are recreated in set_resize as a
|
||||
* central place, so use that to trigger swapchain reinit. */
|
||||
*resize = wl->vk.need_new_swapchain;
|
||||
*resize = wl->vk.flags & VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
|
||||
gfx_ctx_wl_check_window_common(wl, gfx_ctx_wl_get_video_size, quit, resize,
|
||||
width, height);
|
||||
@ -96,10 +96,10 @@ static bool gfx_ctx_wl_set_resize(void *data, unsigned width, unsigned height)
|
||||
if (vulkan_create_swapchain(&wl->vk, width, height, wl->swap_interval))
|
||||
{
|
||||
wl->vk.context.invalid_swapchain = true;
|
||||
if (wl->vk.created_new_swapchain)
|
||||
if (wl->vk.flags & VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN)
|
||||
vulkan_acquire_next_image(&wl->vk);
|
||||
|
||||
wl->vk.need_new_swapchain = false;
|
||||
wl->vk.flags &= ~VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
|
||||
wl_surface_set_buffer_scale(wl->surface, wl->buffer_scale);
|
||||
|
||||
@ -196,7 +196,7 @@ static void gfx_ctx_wl_set_swap_interval(void *data, int swap_interval)
|
||||
{
|
||||
wl->swap_interval = swap_interval;
|
||||
if (wl->vk.swapchain)
|
||||
wl->vk.need_new_swapchain = true;
|
||||
wl->vk.flags |= VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ static void gfx_ctx_x_vk_swap_interval(void *data, int interval)
|
||||
{
|
||||
x->interval = interval;
|
||||
if (x->vk.swapchain)
|
||||
x->vk.need_new_swapchain = true;
|
||||
x->vk.flags |= VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ static void gfx_ctx_x_vk_check_window(void *data, bool *quit,
|
||||
gfx_ctx_x_vk_data_t *x = (gfx_ctx_x_vk_data_t*)data;
|
||||
x11_check_window(data, quit, resize, width, height);
|
||||
|
||||
if (x->vk.need_new_swapchain)
|
||||
if (x->vk.flags & VK_DATA_FLAG_NEED_NEW_SWAPCHAIN)
|
||||
*resize = true;
|
||||
}
|
||||
|
||||
@ -198,10 +198,10 @@ static bool gfx_ctx_x_vk_set_resize(void *data,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x->vk.created_new_swapchain)
|
||||
if (x->vk.flags & VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN)
|
||||
vulkan_acquire_next_image(&x->vk);
|
||||
x->vk.context.invalid_swapchain = true;
|
||||
x->vk.need_new_swapchain = false;
|
||||
x->vk.flags &= ~VK_DATA_FLAG_NEED_NEW_SWAPCHAIN;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user