summaryrefslogtreecommitdiffstats
path: root/drivers/vulkan/vulkan_context.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/vulkan/vulkan_context.cpp')
-rw-r--r--drivers/vulkan/vulkan_context.cpp65
1 files changed, 45 insertions, 20 deletions
diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp
index 3a1330b331..c1632907eb 100644
--- a/drivers/vulkan/vulkan_context.cpp
+++ b/drivers/vulkan/vulkan_context.cpp
@@ -504,6 +504,10 @@ Error VulkanContext::_initialize_device_extensions() {
register_requested_device_extension(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME, false);
register_requested_device_extension(VK_KHR_MAINTENANCE_2_EXTENSION_NAME, false);
+ if (Engine::get_singleton()->is_generate_spirv_debug_info_enabled()) {
+ register_requested_device_extension(VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME, true);
+ }
+
// TODO consider the following extensions:
// - VK_KHR_spirv_1_4
// - VK_KHR_swapchain_mutable_format
@@ -1195,12 +1199,15 @@ Error VulkanContext::_create_physical_device(VkSurfaceKHR p_surface) {
VkQueueFamilyProperties *device_queue_props = (VkQueueFamilyProperties *)malloc(device_queue_family_count * sizeof(VkQueueFamilyProperties));
vkGetPhysicalDeviceQueueFamilyProperties(physical_devices[i], &device_queue_family_count, device_queue_props);
for (uint32_t j = 0; j < device_queue_family_count; j++) {
- VkBool32 supports;
- vkGetPhysicalDeviceSurfaceSupportKHR(physical_devices[i], j, p_surface, &supports);
- if (supports && ((device_queue_props[j].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0)) {
- present_supported = true;
- } else {
- continue;
+ if ((device_queue_props[j].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) {
+ VkBool32 supports;
+ err = vkGetPhysicalDeviceSurfaceSupportKHR(
+ physical_devices[i], j, p_surface, &supports);
+ if (err == VK_SUCCESS && supports) {
+ present_supported = true;
+ } else {
+ continue;
+ }
}
}
String name = props.deviceName;
@@ -1697,17 +1704,6 @@ Error VulkanContext::_window_create(DisplayServer::WindowID p_window_id, Display
Error err = _update_swap_chain(&window);
ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE);
- VkSemaphoreCreateInfo semaphoreCreateInfo = {
- /*sType*/ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
- /*pNext*/ nullptr,
- /*flags*/ 0,
- };
-
- for (uint32_t i = 0; i < FRAME_LAG; i++) {
- VkResult vkerr = vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &window.image_acquired_semaphores[i]);
- ERR_FAIL_COND_V(vkerr, ERR_CANT_CREATE);
- }
-
windows[p_window_id] = window;
return OK;
}
@@ -1757,9 +1753,6 @@ VkFramebuffer VulkanContext::window_get_framebuffer(DisplayServer::WindowID p_wi
void VulkanContext::window_destroy(DisplayServer::WindowID p_window_id) {
ERR_FAIL_COND(!windows.has(p_window_id));
_clean_up_swap_chain(&windows[p_window_id]);
- for (uint32_t i = 0; i < FRAME_LAG; i++) {
- vkDestroySemaphore(device, windows[p_window_id].image_acquired_semaphores[i], nullptr);
- }
vkDestroySurfaceKHR(inst, windows[p_window_id].surface, nullptr);
windows.erase(p_window_id);
@@ -1789,6 +1782,17 @@ Error VulkanContext::_clean_up_swap_chain(Window *window) {
if (separate_present_queue) {
vkDestroyCommandPool(device, window->present_cmd_pool, nullptr);
}
+
+ for (uint32_t i = 0; i < FRAME_LAG; i++) {
+ // Destroy the semaphores now (we'll re-create it later if we have to).
+ // We must do this because the semaphore cannot be reused if it's in a signaled state
+ // (which happens if vkAcquireNextImageKHR returned VK_ERROR_OUT_OF_DATE_KHR or VK_SUBOPTIMAL_KHR)
+ // The only way to reset it would be to present the swapchain... the one we just destroyed.
+ // And the API has no way to "unsignal" the semaphore.
+ vkDestroySemaphore(device, window->image_acquired_semaphores[i], nullptr);
+ window->image_acquired_semaphores[i] = 0;
+ }
+
return OK;
}
@@ -1804,6 +1808,16 @@ Error VulkanContext::_update_swap_chain(Window *window) {
err = fpGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu, window->surface, &surfCapabilities);
ERR_FAIL_COND_V(err, ERR_CANT_CREATE);
+ {
+ VkBool32 supports = VK_FALSE;
+ err = vkGetPhysicalDeviceSurfaceSupportKHR(
+ gpu, present_queue_family_index, window->surface, &supports);
+ ERR_FAIL_COND_V_MSG(err != VK_SUCCESS || supports == false, ERR_CANT_CREATE,
+ "Window's surface is not supported by device. Did the GPU go offline? Was the window "
+ "created on another monitor? Check previous errors & try launching with "
+ "--gpu-validation.");
+ }
+
uint32_t presentModeCount;
err = fpGetPhysicalDeviceSurfacePresentModesKHR(gpu, window->surface, &presentModeCount, nullptr);
ERR_FAIL_COND_V(err, ERR_CANT_CREATE);
@@ -2162,6 +2176,17 @@ Error VulkanContext::_update_swap_chain(Window *window) {
// Reset current buffer.
window->current_buffer = 0;
+ VkSemaphoreCreateInfo semaphoreCreateInfo = {
+ /*sType*/ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
+ /*pNext*/ nullptr,
+ /*flags*/ 0,
+ };
+
+ for (uint32_t i = 0; i < FRAME_LAG; i++) {
+ VkResult vkerr = vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &window->image_acquired_semaphores[i]);
+ ERR_FAIL_COND_V(vkerr, ERR_CANT_CREATE);
+ }
+
return OK;
}