(Vulkan/Wayland) Cleanups

This commit is contained in:
libretroadmin 2023-06-20 08:20:13 +02:00
parent 45a2736958
commit 16fcd1d62c
2 changed files with 153 additions and 143 deletions

View File

@ -86,15 +86,11 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL vulkan_debug_cb(
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
void *pUserData) void *pUserData)
{ {
const char *name; if ( (messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
(void)pUserData; && (messageType == VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT))
if (messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT &&
messageType == VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT)
{ {
RARCH_ERR("[Vulkan]: Validation Error: %s\n", pCallbackData->pMessage); RARCH_ERR("[Vulkan]: Validation Error: %s\n", pCallbackData->pMessage);
} }
return VK_FALSE; return VK_FALSE;
} }
#endif #endif
@ -207,24 +203,18 @@ static void vulkan_emulated_mailbox_loop(void *userdata)
mailbox->flags &= ~VK_MAILBOX_FLAG_REQUEST_ACQUIRE; mailbox->flags &= ~VK_MAILBOX_FLAG_REQUEST_ACQUIRE;
slock_unlock(mailbox->lock); slock_unlock(mailbox->lock);
#ifdef ANDROID
mailbox->result = vkAcquireNextImageKHR( mailbox->result = vkAcquireNextImageKHR(
mailbox->device, mailbox->swapchain, UINT64_MAX, mailbox->device, mailbox->swapchain, UINT64_MAX,
VK_NULL_HANDLE, fence, &mailbox->index); VK_NULL_HANDLE, fence, &mailbox->index);
#ifdef ANDROID
/* VK_SUBOPTIMAL_KHR can be returned on Android 10 /* VK_SUBOPTIMAL_KHR can be returned on Android 10
* when prerotate is not dealt with. * when prerotate is not dealt with.
* This is not an error we need to care about, * This is not an error we need to care about,
* and we'll treat it as SUCCESS. */ * and we'll treat it as SUCCESS. */
if (mailbox->result == VK_SUBOPTIMAL_KHR) if (mailbox->result == VK_SUBOPTIMAL_KHR)
mailbox->result = VK_SUCCESS; mailbox->result = VK_SUCCESS;
if (mailbox->result == VK_SUCCESS)
#else
if ((mailbox->result = vkAcquireNextImageKHR(
mailbox->device, mailbox->swapchain, UINT64_MAX,
VK_NULL_HANDLE, fence, &mailbox->index)) == VK_SUCCESS)
#endif #endif
if (mailbox->result == VK_SUCCESS)
{ {
vkWaitForFences(mailbox->device, 1, &fence, true, UINT64_MAX); vkWaitForFences(mailbox->device, 1, &fence, true, UINT64_MAX);
vkResetFences(mailbox->device, 1, &fence); vkResetFences(mailbox->device, 1, &fence);
@ -567,13 +557,13 @@ static bool vulkan_context_init_device(gfx_ctx_vulkan_data_t *vk)
uint32_t queue_count; uint32_t queue_count;
unsigned i; unsigned i;
const char *enabled_device_extensions[8]; const char *enabled_device_extensions[8];
VkDeviceCreateInfo device_info;
VkDeviceQueueCreateInfo queue_info;
static const float one = 1.0f; static const float one = 1.0f;
bool found_queue = false; bool found_queue = false;
video_driver_state_t *video_st = video_state_get_ptr(); video_driver_state_t *video_st = video_state_get_ptr();
VkPhysicalDeviceFeatures features = { false }; VkPhysicalDeviceFeatures features = { false };
VkDeviceQueueCreateInfo queue_info = { VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO };
VkDeviceCreateInfo device_info = { VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO };
unsigned enabled_device_extension_count = 0; unsigned enabled_device_extension_count = 0;
@ -581,20 +571,39 @@ static bool vulkan_context_init_device(gfx_ctx_vulkan_data_t *vk)
*iface = (struct retro_hw_render_context_negotiation_interface_vulkan*) *iface = (struct retro_hw_render_context_negotiation_interface_vulkan*)
video_st->hw_render_context_negotiation; video_st->hw_render_context_negotiation;
if (iface && iface->interface_type != RETRO_HW_RENDER_CONTEXT_NEGOTIATION_INTERFACE_VULKAN) queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
{ queue_info.pNext = NULL;
RARCH_WARN("[Vulkan]: Got HW context negotiation interface, but it's the wrong API.\n"); queue_info.flags = 0;
iface = NULL; queue_info.queueFamilyIndex = 0;
} queue_info.queueCount = 0;
queue_info.pQueuePriorities = NULL;
if (iface && iface->interface_version == 0) device_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
{ device_info.pNext = NULL;
RARCH_WARN("[Vulkan]: Got HW context negotiation interface, but it's the wrong interface version.\n"); device_info.flags = 0;
iface = NULL; device_info.queueCreateInfoCount = 0;
} device_info.pQueueCreateInfos = NULL;
device_info.enabledLayerCount = 0;
device_info.ppEnabledLayerNames = NULL;
device_info.enabledExtensionCount = 0;
device_info.ppEnabledExtensionNames = NULL;
device_info.pEnabledFeatures = NULL;
if (iface) if (iface)
RARCH_LOG("[Vulkan]: Got HW context negotiation interface %u.\n", iface->interface_version); {
if (iface->interface_type != RETRO_HW_RENDER_CONTEXT_NEGOTIATION_INTERFACE_VULKAN)
{
RARCH_WARN("[Vulkan]: Got HW context negotiation interface, but it's the wrong API.\n");
iface = NULL;
}
else if (iface->interface_version == 0)
{
RARCH_WARN("[Vulkan]: Got HW context negotiation interface, but it's the wrong interface version.\n");
iface = NULL;
}
else
RARCH_LOG("[Vulkan]: Got HW context negotiation interface %u.\n", iface->interface_version);
}
if (!vulkan_context_init_gpu(vk)) if (!vulkan_context_init_gpu(vk))
return false; return false;
@ -605,7 +614,8 @@ static bool vulkan_context_init_device(gfx_ctx_vulkan_data_t *vk)
bool ret = false; bool ret = false;
if (iface->interface_version >= 2 && iface->create_device2) if ( (iface->interface_version >= 2)
&& iface->create_device2)
{ {
ret = iface->create_device2(&context, vk->context.instance, ret = iface->create_device2(&context, vk->context.instance,
vk->context.gpu, vk->context.gpu,
@ -897,8 +907,8 @@ static VkInstance vulkan_context_create_instance_wrapper(void *opaque, const VkI
/* Be careful about validating supported instance extensions when using explicit layers. /* Be careful about validating supported instance extensions when using explicit layers.
* If core wants to enable debug layers, we'll have to do deeper validation and query * If core wants to enable debug layers, we'll have to do deeper validation and query
* supported extensions per-layer which is annoying. vkCreateInstance will validate this on its own anyways. */ * supported extensions per-layer which is annoying. vkCreateInstance will validate this on its own anyways. */
if (info.enabledLayerCount == 0 && if ( (info.enabledLayerCount == 0)
!vulkan_find_instance_extensions(info.ppEnabledExtensionNames, info.enabledExtensionCount)) && !vulkan_find_instance_extensions(info.ppEnabledExtensionNames, info.enabledExtensionCount))
{ {
RARCH_ERR("[Vulkan]: Instance does not support required extensions.\n"); RARCH_ERR("[Vulkan]: Instance does not support required extensions.\n");
goto end; goto end;
@ -959,13 +969,13 @@ static bool vulkan_update_display_mode(
else else
{ {
/* For particular resolutions, find the closest. */ /* For particular resolutions, find the closest. */
int delta_x = (int)info->width - (int)visible_width; int delta_x = (int)info->width - (int)visible_width;
int delta_y = (int)info->height - (int)visible_height; int delta_y = (int)info->height - (int)visible_height;
int delta_rate = abs((int)info->refresh_rate_x1000 - (int)visible_rate); int old_delta_x = (int)info->width - (int)*width;
int old_delta_x = (int)info->width - (int)*width;
int old_delta_y = (int)info->height - (int)*height; int old_delta_y = (int)info->height - (int)*height;
int delta_rate = abs((int)info->refresh_rate_x1000 - (int)visible_rate);
int dist = delta_x * delta_x + delta_y * delta_y; int dist = delta_x * delta_x + delta_y * delta_y;
int old_dist = old_delta_x * old_delta_x + old_delta_y * old_delta_y; int old_dist = old_delta_x * old_delta_x + old_delta_y * old_delta_y;
if (dist < old_dist && delta_rate < 1000) if (dist < old_dist && delta_rate < 1000)
@ -983,6 +993,7 @@ static bool vulkan_create_display_surface(gfx_ctx_vulkan_data_t *vk,
unsigned *width, unsigned *height, unsigned *width, unsigned *height,
const struct vulkan_display_surface_info *info) const struct vulkan_display_surface_info *info)
{ {
unsigned dpy, i, j;
bool ret = true; bool ret = true;
uint32_t display_count = 0; uint32_t display_count = 0;
uint32_t plane_count = 0; uint32_t plane_count = 0;
@ -990,7 +1001,6 @@ static bool vulkan_create_display_surface(gfx_ctx_vulkan_data_t *vk,
VkDisplayPlanePropertiesKHR *planes = NULL; VkDisplayPlanePropertiesKHR *planes = NULL;
uint32_t mode_count = 0; uint32_t mode_count = 0;
VkDisplayModePropertiesKHR *modes = NULL; VkDisplayModePropertiesKHR *modes = NULL;
unsigned dpy, i, j;
uint32_t best_plane = UINT32_MAX; uint32_t best_plane = UINT32_MAX;
VkDisplayPlaneAlphaFlagBitsKHR alpha_mode = VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR; VkDisplayPlaneAlphaFlagBitsKHR alpha_mode = VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR;
VkDisplaySurfaceCreateInfoKHR create_info = { VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR }; VkDisplaySurfaceCreateInfoKHR create_info = { VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR };
@ -1108,8 +1118,8 @@ retry:
if (j == supported_count) if (j == supported_count)
continue; continue;
if ( planes[i].currentDisplay == VK_NULL_HANDLE if ( (planes[i].currentDisplay == VK_NULL_HANDLE)
|| planes[i].currentDisplay == display) || (planes[i].currentDisplay == display))
best_plane = j; best_plane = j;
else else
continue; continue;
@ -1117,7 +1127,8 @@ retry:
vkGetDisplayPlaneCapabilitiesKHR(vk->context.gpu, vkGetDisplayPlaneCapabilitiesKHR(vk->context.gpu,
best_mode, i, &plane_caps); best_mode, i, &plane_caps);
if (plane_caps.supportedAlpha & VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR) if ( plane_caps.supportedAlpha
& VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR)
{ {
best_plane = j; best_plane = j;
alpha_mode = VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR; alpha_mode = VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR;
@ -1127,7 +1138,8 @@ retry:
} }
out: out:
if (best_plane == UINT32_MAX && monitor_index != 0) if ( (best_plane == UINT32_MAX)
&& (monitor_index != 0))
{ {
RARCH_WARN("Could not find suitable surface for monitor index: %u.\n", RARCH_WARN("Could not find suitable surface for monitor index: %u.\n",
monitor_index); monitor_index);
@ -1219,7 +1231,7 @@ static void vulkan_acquire_clear_fences(gfx_ctx_vulkan_data_t *vk)
{ {
vkDestroyFence(vk->context.device, vkDestroyFence(vk->context.device,
vk->context.swapchain_fences[i], NULL); vk->context.swapchain_fences[i], NULL);
vk->context.swapchain_fences[i] = VK_NULL_HANDLE; vk->context.swapchain_fences[i] = VK_NULL_HANDLE;
} }
vk->context.swapchain_fences_signalled[i] = false; vk->context.swapchain_fences_signalled[i] = false;
@ -1325,7 +1337,7 @@ bool vulkan_buffer_chain_alloc(const struct vulkan_context *context,
return false; return false;
chain->current = chain->head; chain->current = chain->head;
chain->offset = 0; chain->offset = 0;
} }
if (!vulkan_buffer_chain_suballoc(chain, size, range)) if (!vulkan_buffer_chain_suballoc(chain, size, range))
@ -1344,7 +1356,7 @@ bool vulkan_buffer_chain_alloc(const struct vulkan_context *context,
* buffer here than block_size in case we have * buffer here than block_size in case we have
* a very large allocation. */ * a very large allocation. */
if (size < chain->block_size) if (size < chain->block_size)
size = chain->block_size; size = chain->block_size;
if (!(chain->current->next = vulkan_buffer_chain_alloc_node( if (!(chain->current->next = vulkan_buffer_chain_alloc_node(
context, size, chain->usage))) context, size, chain->usage)))
@ -1418,9 +1430,7 @@ struct vk_buffer vulkan_create_buffer(
return buffer; return buffer;
} }
void vulkan_destroy_buffer( void vulkan_destroy_buffer(VkDevice device, struct vk_buffer *buffer)
VkDevice device,
struct vk_buffer *buffer)
{ {
vkUnmapMemory(device, buffer->memory); vkUnmapMemory(device, buffer->memory);
vkFreeMemory(device, buffer->memory, NULL); vkFreeMemory(device, buffer->memory, NULL);
@ -1437,31 +1447,31 @@ struct vk_descriptor_pool *vulkan_alloc_descriptor_pool(
unsigned i; unsigned i;
VkDescriptorPoolCreateInfo pool_info; VkDescriptorPoolCreateInfo pool_info;
VkDescriptorSetAllocateInfo alloc_info; VkDescriptorSetAllocateInfo alloc_info;
struct vk_descriptor_pool *pool = struct vk_descriptor_pool *pool =
(struct vk_descriptor_pool*)malloc(sizeof(*pool)); (struct vk_descriptor_pool*)malloc(sizeof(*pool));
if (!pool) if (!pool)
return NULL; return NULL;
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
pool_info.pNext = NULL; pool_info.pNext = NULL;
pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
pool_info.maxSets = VULKAN_DESCRIPTOR_MANAGER_BLOCK_SETS; pool_info.maxSets = VULKAN_DESCRIPTOR_MANAGER_BLOCK_SETS;
pool_info.poolSizeCount = manager->num_sizes; pool_info.poolSizeCount = manager->num_sizes;
pool_info.pPoolSizes = manager->sizes; pool_info.pPoolSizes = manager->sizes;
pool->pool = VK_NULL_HANDLE; pool->pool = VK_NULL_HANDLE;
for (i = 0; i < VULKAN_DESCRIPTOR_MANAGER_BLOCK_SETS; i++) for (i = 0; i < VULKAN_DESCRIPTOR_MANAGER_BLOCK_SETS; i++)
pool->sets[i] = VK_NULL_HANDLE; pool->sets[i] = VK_NULL_HANDLE;
pool->next = NULL; pool->next = NULL;
vkCreateDescriptorPool(device, &pool_info, NULL, &pool->pool); vkCreateDescriptorPool(device, &pool_info, NULL, &pool->pool);
/* Just allocate all descriptor sets up front. */ /* Just allocate all descriptor sets up front. */
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
alloc_info.pNext = NULL; alloc_info.pNext = NULL;
alloc_info.descriptorPool = pool->pool; alloc_info.descriptorPool = pool->pool;
alloc_info.descriptorSetCount = 1; alloc_info.descriptorSetCount = 1;
alloc_info.pSetLayouts = &manager->set_layout; alloc_info.pSetLayouts = &manager->set_layout;
for (i = 0; i < VULKAN_DESCRIPTOR_MANAGER_BLOCK_SETS; i++) for (i = 0; i < VULKAN_DESCRIPTOR_MANAGER_BLOCK_SETS; i++)
vkAllocateDescriptorSets(device, &alloc_info, &pool->sets[i]); vkAllocateDescriptorSets(device, &alloc_info, &pool->sets[i]);
@ -1699,8 +1709,8 @@ uint32_t vulkan_find_memory_type(
uint32_t i; uint32_t i;
for (i = 0; i < VK_MAX_MEMORY_TYPES; i++) for (i = 0; i < VK_MAX_MEMORY_TYPES; i++)
{ {
if ((device_reqs & (1u << i)) && if ( (device_reqs & (1u << i))
(mem_props->memoryTypes[i].propertyFlags & host_reqs) == host_reqs) && (mem_props->memoryTypes[i].propertyFlags & host_reqs) == host_reqs)
return i; return i;
} }
@ -1716,8 +1726,8 @@ uint32_t vulkan_find_memory_type_fallback(
uint32_t i; uint32_t i;
for (i = 0; i < VK_MAX_MEMORY_TYPES; i++) for (i = 0; i < VK_MAX_MEMORY_TYPES; i++)
{ {
if ((device_reqs & (1u << i)) && if ( (device_reqs & (1u << i))
(mem_props->memoryTypes[i].propertyFlags & host_reqs_first) == host_reqs_first) && (mem_props->memoryTypes[i].propertyFlags & host_reqs_first) == host_reqs_first)
return i; return i;
} }
@ -1895,21 +1905,24 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
{ {
unsigned i; unsigned i;
uint32_t format_count; uint32_t format_count;
uint32_t present_mode_count;
uint32_t desired_swapchain_images; uint32_t desired_swapchain_images;
VkSurfaceCapabilitiesKHR surface_properties; VkSurfaceCapabilitiesKHR surface_properties;
VkSurfaceFormatKHR formats[256]; VkSurfaceFormatKHR formats[256];
VkPresentModeKHR present_modes[16]; VkPresentModeKHR present_modes[16];
VkExtent2D swapchain_size; VkExtent2D swapchain_size;
VkSurfaceFormatKHR format;
VkSwapchainKHR old_swapchain; VkSwapchainKHR old_swapchain;
VkSwapchainCreateInfoKHR info; VkSwapchainCreateInfoKHR info;
VkSurfaceTransformFlagBitsKHR pre_transform; VkSurfaceTransformFlagBitsKHR pre_transform;
VkSurfaceFormatKHR format = { VK_FORMAT_UNDEFINED, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR }; uint32_t present_mode_count = 0;
VkPresentModeKHR swapchain_present_mode = VK_PRESENT_MODE_FIFO_KHR; VkPresentModeKHR swapchain_present_mode = VK_PRESENT_MODE_FIFO_KHR;
VkCompositeAlphaFlagBitsKHR composite = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; VkCompositeAlphaFlagBitsKHR composite = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
bool vsync = settings->bools.video_vsync; bool vsync = settings->bools.video_vsync;
format.format = VK_FORMAT_UNDEFINED;
format.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
vkDeviceWaitIdle(vk->context.device); vkDeviceWaitIdle(vk->context.device);
vulkan_acquire_clear_fences(vk); vulkan_acquire_clear_fences(vk);
@ -1917,8 +1930,8 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
vk->vk_surface, &surface_properties); vk->vk_surface, &surface_properties);
/* Skip creation when window is minimized */ /* Skip creation when window is minimized */
if (!surface_properties.currentExtent.width && if ( !surface_properties.currentExtent.width
!surface_properties.currentExtent.height) && !surface_properties.currentExtent.height)
return false; return false;
if ( (swap_interval == 0) if ( (swap_interval == 0)
@ -1988,7 +2001,6 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
vulkan_emulated_mailbox_deinit(&vk->mailbox); vulkan_emulated_mailbox_deinit(&vk->mailbox);
present_mode_count = 0;
vkGetPhysicalDeviceSurfacePresentModesKHR( vkGetPhysicalDeviceSurfacePresentModesKHR(
vk->context.gpu, vk->vk_surface, vk->context.gpu, vk->vk_surface,
&present_mode_count, NULL); &present_mode_count, NULL);
@ -2012,18 +2024,20 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
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++)
{ {
if (!swap_interval && present_modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) if ( !swap_interval
&& (present_modes[i] == VK_PRESENT_MODE_MAILBOX_KHR))
{ {
swapchain_present_mode = VK_PRESENT_MODE_MAILBOX_KHR; swapchain_present_mode = VK_PRESENT_MODE_MAILBOX_KHR;
break; break;
} }
else if (!swap_interval && present_modes[i] else if (!swap_interval
== VK_PRESENT_MODE_IMMEDIATE_KHR) && (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 && 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;
@ -2042,7 +2056,8 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
vk->vk_surface, &format_count, formats); vk->vk_surface, &format_count, formats);
format.format = VK_FORMAT_UNDEFINED; format.format = VK_FORMAT_UNDEFINED;
if (format_count == 1 && formats[0].format == VK_FORMAT_UNDEFINED) if ( format_count == 1
&& (formats[0].format == VK_FORMAT_UNDEFINED))
{ {
format = formats[0]; format = formats[0];
format.format = VK_FORMAT_B8G8R8A8_UNORM; format.format = VK_FORMAT_B8G8R8A8_UNORM;
@ -2065,7 +2080,8 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
for (i = 0; i < format_count; i++) for (i = 0; i < format_count; i++)
{ {
if (formats[i].format == VK_FORMAT_A2B10G10R10_UNORM_PACK32 && formats[i].colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT) if ( (formats[i].format == VK_FORMAT_A2B10G10R10_UNORM_PACK32)
&& (formats[i].colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT))
{ {
format = formats[i]; format = formats[i];
video_driver_set_hdr_support(); video_driver_set_hdr_support();
@ -2124,7 +2140,8 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
if (swapchain_size.height < surface_properties.minImageExtent.height) if (swapchain_size.height < surface_properties.minImageExtent.height)
swapchain_size.height = surface_properties.minImageExtent.height; swapchain_size.height = surface_properties.minImageExtent.height;
if (swapchain_size.width == 0 && swapchain_size.height == 0) if ( (swapchain_size.width == 0)
&& (swapchain_size.height == 0))
{ {
/* Cannot create swapchain yet, try again later. */ /* Cannot create swapchain yet, try again later. */
if (vk->swapchain != VK_NULL_HANDLE) if (vk->swapchain != VK_NULL_HANDLE)
@ -2155,7 +2172,7 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
* because MESA always reports a minImageCount of 4, but 3 and 2 work * because MESA always reports a minImageCount of 4, but 3 and 2 work
* pefectly well, even if it's out of spec. */ * pefectly well, even if it's out of spec. */
if ((surface_properties.maxImageCount > 0) if ( (surface_properties.maxImageCount > 0)
&& (desired_swapchain_images > surface_properties.maxImageCount)) && (desired_swapchain_images > surface_properties.maxImageCount))
desired_swapchain_images = surface_properties.maxImageCount; desired_swapchain_images = surface_properties.maxImageCount;
@ -2339,38 +2356,41 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
app.engineVersion = 0; app.engineVersion = 0;
app.apiVersion = VK_API_VERSION_1_0; app.apiVersion = VK_API_VERSION_1_0;
if (iface && !iface->get_application_info && iface->interface_version >= 2) if (iface)
{ {
RARCH_ERR("[Vulkan]: Core did not provide application info as required by v2.\n"); if (!iface->get_application_info && iface->interface_version >= 2)
return false;
}
if (iface && iface->get_application_info)
{
const VkApplicationInfo *app_info = iface->get_application_info();
if (!app_info && iface->interface_version >= 2)
{ {
RARCH_ERR("[Vulkan]: Core did not provide application info as required by v2.\n"); RARCH_ERR("[Vulkan]: Core did not provide application info as required by v2.\n");
return false; return false;
} }
if (app_info) if (iface->get_application_info)
{ {
app = *app_info; const VkApplicationInfo *app_info = iface->get_application_info();
#ifdef VULKAN_DEBUG
if (app.pApplicationName) if (!app_info && iface->interface_version >= 2)
{ {
RARCH_LOG("[Vulkan]: App: %s (version %u)\n", RARCH_ERR("[Vulkan]: Core did not provide application info as required by v2.\n");
app.pApplicationName, app.applicationVersion); return false;
} }
if (app.pEngineName) if (app_info)
{ {
RARCH_LOG("[Vulkan]: Engine: %s (version %u)\n", app = *app_info;
app.pEngineName, app.engineVersion); #ifdef VULKAN_DEBUG
} if (app.pApplicationName)
{
RARCH_LOG("[Vulkan]: App: %s (version %u)\n",
app.pApplicationName, app.applicationVersion);
}
if (app.pEngineName)
{
RARCH_LOG("[Vulkan]: Engine: %s (version %u)\n",
app.pEngineName, app.engineVersion);
}
#endif #endif
}
} }
} }
@ -2379,12 +2399,10 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
/* Try to upgrade to at least Vulkan 1.1 so that we can more easily make use of advanced features. /* Try to upgrade to at least Vulkan 1.1 so that we can more easily make use of advanced features.
* Vulkan 1.0 drivers are completely irrelevant these days. */ * Vulkan 1.0 drivers are completely irrelevant these days. */
uint32_t supported; uint32_t supported;
if (vkEnumerateInstanceVersion && if ( vkEnumerateInstanceVersion
vkEnumerateInstanceVersion(&supported) == VK_SUCCESS && && (vkEnumerateInstanceVersion(&supported) == VK_SUCCESS)
supported >= VK_API_VERSION_1_1) && (supported >= VK_API_VERSION_1_1))
{
app.apiVersion = VK_API_VERSION_1_1; app.apiVersion = VK_API_VERSION_1_1;
}
} }
if (cached_instance_vk) if (cached_instance_vk)
@ -2394,7 +2412,9 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
} }
else else
{ {
if (iface && iface->interface_version >= 2 && iface->create_instance) if ( iface
&& iface->interface_version >= 2
&& iface->create_instance)
vk->context.instance = iface->create_instance( vk->context.instance = iface->create_instance(
GetInstanceProcAddr, &app, GetInstanceProcAddr, &app,
vulkan_context_create_instance_wrapper, vk); vulkan_context_create_instance_wrapper, vk);
@ -2433,10 +2453,8 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
info.pfnUserCallback = vulkan_debug_cb; info.pfnUserCallback = vulkan_debug_cb;
if (vk->context.instance) if (vk->context.instance)
{
vkCreateDebugUtilsMessengerEXT(vk->context.instance, &info, NULL, vkCreateDebugUtilsMessengerEXT(vk->context.instance, &info, NULL,
&vk->context.debug_callback); &vk->context.debug_callback);
}
} }
RARCH_LOG("[Vulkan]: Enabling Vulkan debug layers.\n"); RARCH_LOG("[Vulkan]: Enabling Vulkan debug layers.\n");
#endif #endif
@ -2464,7 +2482,8 @@ void vulkan_context_destroy(gfx_ctx_vulkan_data_t *vk,
vulkan_destroy_swapchain(vk); vulkan_destroy_swapchain(vk);
if (destroy_surface && vk->vk_surface != VK_NULL_HANDLE) if ( destroy_surface
&& (vk->vk_surface != VK_NULL_HANDLE))
{ {
vkDestroySurfaceKHR(vk->context.instance, vkDestroySurfaceKHR(vk->context.instance,
vk->vk_surface, NULL); vk->vk_surface, NULL);
@ -2476,7 +2495,7 @@ void vulkan_context_destroy(gfx_ctx_vulkan_data_t *vk,
vkDestroyDebugUtilsMessengerEXT(vk->context.instance, vk->context.debug_callback, NULL); vkDestroyDebugUtilsMessengerEXT(vk->context.instance, vk->context.debug_callback, NULL);
#endif #endif
video_st_flags = video_st->flags; video_st_flags = video_st->flags;
if (video_st_flags & VIDEO_FLAG_CACHE_CONTEXT) if (video_st_flags & VIDEO_FLAG_CACHE_CONTEXT)
{ {

View File

@ -79,11 +79,6 @@ static const unsigned long retroarch_icon_data[] = {
0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
}; };
static void update_viewport(gfx_ctx_wayland_data_t *wl)
{
wp_viewport_set_destination(wl->viewport, wl->width, wl->height);
}
void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl, void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl,
void *toplevel, void *toplevel,
int32_t width, int32_t height, struct wl_array *states) int32_t width, int32_t height, struct wl_array *states)
@ -104,8 +99,7 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl,
break; break;
case XDG_TOPLEVEL_STATE_MAXIMIZED: case XDG_TOPLEVEL_STATE_MAXIMIZED:
wl->maximized = true; wl->maximized = true;
floating = false; /* fall-through */
break;
case XDG_TOPLEVEL_STATE_TILED_LEFT: case XDG_TOPLEVEL_STATE_TILED_LEFT:
case XDG_TOPLEVEL_STATE_TILED_RIGHT: case XDG_TOPLEVEL_STATE_TILED_RIGHT:
case XDG_TOPLEVEL_STATE_TILED_TOP: case XDG_TOPLEVEL_STATE_TILED_TOP:
@ -130,13 +124,13 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl,
if ( (width > 0) if ( (width > 0)
&& (height > 0)) && (height > 0))
{ {
wl->width = width; wl->width = width;
wl->height = height; wl->height = height;
wl->buffer_width = wl->width * wl->buffer_scale; wl->buffer_width = wl->width * wl->buffer_scale;
wl->buffer_height = wl->height * wl->buffer_scale; wl->buffer_height = wl->height * wl->buffer_scale;
wl->resize = true; wl->resize = true;
if (wl->viewport) if (wl->viewport) /* Update viewport */
update_viewport(wl); wp_viewport_set_destination(wl->viewport, wl->width, wl->height);
} }
if (floating) if (floating)
@ -198,8 +192,8 @@ void libdecor_frame_handle_configure_common(struct libdecor_frame *frame,
wl->buffer_width = width * wl->buffer_scale; wl->buffer_width = width * wl->buffer_scale;
wl->buffer_height = height * wl->buffer_scale; wl->buffer_height = height * wl->buffer_scale;
wl->resize = true; wl->resize = true;
if (wl->viewport) if (wl->viewport) /* Update viewport */
update_viewport(wl); wp_viewport_set_destination(wl->viewport, wl->width, wl->height);
} }
state = wl->libdecor_state_new(wl->width, wl->height); state = wl->libdecor_state_new(wl->width, wl->height);
@ -219,7 +213,6 @@ void libdecor_frame_handle_commit(struct libdecor_frame *frame,
void *data) { } void *data) { }
#endif #endif
void gfx_ctx_wl_get_video_size_common(void *data, void gfx_ctx_wl_get_video_size_common(void *data,
unsigned *width, unsigned *height) unsigned *width, unsigned *height)
{ {
@ -301,17 +294,14 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl)
wl_data_device_manager_destroy (wl->data_device_manager); wl_data_device_manager_destroy (wl->data_device_manager);
while (!wl_list_empty(&wl->current_outputs)) while (!wl_list_empty(&wl->current_outputs))
{ {
surface_output_t *os; surface_output_t *os = wl_container_of(wl->current_outputs.next, os, link);
os = wl_container_of(wl->current_outputs.next, os, link);
wl_list_remove(&os->link); wl_list_remove(&os->link);
free(os); free(os);
} }
while (!wl_list_empty(&wl->all_outputs)) while (!wl_list_empty(&wl->all_outputs))
{ {
display_output_t *od; display_output_t *od = wl_container_of(wl->all_outputs.next, od, link);
output_info_t *oi; output_info_t *oi = od->output;
od = wl_container_of(wl->all_outputs.next, od, link);
oi = od->output;
wl_output_destroy(oi->output); wl_output_destroy(oi->output);
wl_list_remove(&od->link); wl_list_remove(&od->link);
free(oi); free(oi);
@ -428,8 +418,7 @@ bool gfx_ctx_wl_get_metrics_common(void *data,
static int create_shm_file(off_t size) static int create_shm_file(off_t size)
{ {
int fd; int fd, ret;
int ret;
if ((fd = syscall(SYS_memfd_create, SPLASH_SHM_NAME, if ((fd = syscall(SYS_memfd_create, SPLASH_SHM_NAME,
MFD_CLOEXEC | MFD_ALLOW_SEALING)) >= 0) MFD_CLOEXEC | MFD_ALLOW_SEALING)) >= 0)
{ {
@ -604,11 +593,13 @@ static bool wl_draw_splash_screen(gfx_ctx_wayland_data_t *wl)
bool gfx_ctx_wl_init_common( bool gfx_ctx_wl_init_common(
const toplevel_listener_t *toplevel_listener, gfx_ctx_wayland_data_t **wwl) const toplevel_listener_t *toplevel_listener, gfx_ctx_wayland_data_t **wwl)
{ {
int i;
gfx_ctx_wayland_data_t *wl;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
unsigned video_monitor_index = settings->uints.video_monitor_index; unsigned video_monitor_index = settings->uints.video_monitor_index;
int i;
*wwl = calloc(1, sizeof(gfx_ctx_wayland_data_t)); *wwl = calloc(1, sizeof(gfx_ctx_wayland_data_t));
gfx_ctx_wayland_data_t *wl = *wwl; wl = *wwl;
if (!wl) if (!wl)
return false; return false;
@ -775,7 +766,7 @@ bool gfx_ctx_wl_init_common(
wl->num_active_touches = 0; wl->num_active_touches = 0;
for (i = 0;i < MAX_TOUCHES;i++) for (i = 0; i < MAX_TOUCHES; i++)
{ {
wl->active_touch_positions[i].active = false; wl->active_touch_positions[i].active = false;
wl->active_touch_positions[i].id = -1; wl->active_touch_positions[i].id = -1;
@ -804,12 +795,12 @@ bool gfx_ctx_wl_set_video_mode_common_size(gfx_ctx_wayland_data_t *wl,
if (!fullscreen) if (!fullscreen)
{ {
wl->buffer_scale = wl->pending_buffer_scale; wl->buffer_scale = wl->pending_buffer_scale;
wl->buffer_width *= wl->buffer_scale; wl->buffer_width *= wl->buffer_scale;
wl->buffer_height *= wl->buffer_scale; wl->buffer_height *= wl->buffer_scale;
} }
if (wl->viewport) if (wl->viewport) /* Update viewport */
update_viewport(wl); wp_viewport_set_destination(wl->viewport, wl->width, wl->height);
#ifdef HAVE_LIBDECOR_H #ifdef HAVE_LIBDECOR_H
if (wl->libdecor) if (wl->libdecor)
@ -848,7 +839,7 @@ bool gfx_ctx_wl_set_video_mode_common_fullscreen(gfx_ctx_wayland_data_t *wl,
{ {
if (++output_i == (int)video_monitor_index) if (++output_i == (int)video_monitor_index)
{ {
oi = od->output; oi = od->output;
output = oi->output; output = oi->output;
RARCH_LOG("[Wayland]: Fullscreen on display %i \"%s\" \"%s\"\n", output_i, oi->make, oi->model); RARCH_LOG("[Wayland]: Fullscreen on display %i \"%s\" \"%s\"\n", output_i, oi->make, oi->model);
break; break;
@ -937,9 +928,9 @@ void gfx_ctx_wl_check_window_common(gfx_ctx_wayland_data_t *wl,
|| new_height != *height) || new_height != *height)
{ {
wl->buffer_scale = wl->pending_buffer_scale; wl->buffer_scale = wl->pending_buffer_scale;
*width = new_width; *width = new_width;
*height = new_height; *height = new_height;
*resize = true; *resize = true;
} }
*quit = (bool)frontend_driver_get_signal_handler_state(); *quit = (bool)frontend_driver_get_signal_handler_state();