From 1eafc330527ae738dd2e088ca4837cded151c067 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 13 Jul 2019 00:36:21 +0900 Subject: [PATCH] Ensure vulkan gets shut down --- include/QF/Vulkan/device.h | 5 +++-- include/QF/Vulkan/funclist.h | 6 ++++++ include/QF/Vulkan/swapchain.h | 1 + libs/video/renderer/r_init.c | 9 +++++++++ libs/video/renderer/vulkan/device.c | 17 ++++++++--------- libs/video/renderer/vulkan/swapchain.c | 8 ++++++++ libs/video/renderer/vulkan/vulkan_vid_common.c | 2 ++ 7 files changed, 37 insertions(+), 11 deletions(-) diff --git a/include/QF/Vulkan/device.h b/include/QF/Vulkan/device.h index ae0c26ffc..8dc4df371 100644 --- a/include/QF/Vulkan/device.h +++ b/include/QF/Vulkan/device.h @@ -20,7 +20,8 @@ typedef struct qfv_device_s { } qfv_device_t; struct vulkan_ctx_s; -qfv_device_t *QFV_CreateDevice(struct vulkan_ctx_s *ctx, - const char **extensions); +qfv_device_t *QFV_CreateDevice (struct vulkan_ctx_s *ctx, + const char **extensions); +void QFV_DestroyDevice (qfv_device_t *device); #endif//__QF_Vulkan_swapchain_h diff --git a/include/QF/Vulkan/funclist.h b/include/QF/Vulkan/funclist.h index 1419aebd4..43bad39c7 100644 --- a/include/QF/Vulkan/funclist.h +++ b/include/QF/Vulkan/funclist.h @@ -48,6 +48,8 @@ INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION (vkGetPhysicalDeviceSurfaceCapabilitiesKHR, VK_KHR_SURFACE_EXTENSION_NAME) INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION (vkGetPhysicalDeviceSurfaceFormatsKHR, VK_KHR_SURFACE_EXTENSION_NAME) +INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION + (vkDestroySurfaceKHR, VK_KHR_SURFACE_EXTENSION_NAME) #undef INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION @@ -99,5 +101,9 @@ DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION (vkDestroySwapchainKHR, VK_KHR_SWAPCHAIN_EXTENSION_NAME) DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION (vkGetSwapchainImagesKHR, VK_KHR_SWAPCHAIN_EXTENSION_NAME) +DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION + (vkAcquireNextImageKHR, VK_KHR_SWAPCHAIN_EXTENSION_NAME) +DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION + (vkQueuePresentKHR, VK_KHR_SWAPCHAIN_EXTENSION_NAME) #undef DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION diff --git a/include/QF/Vulkan/swapchain.h b/include/QF/Vulkan/swapchain.h index 71d0b6d75..91d158c89 100644 --- a/include/QF/Vulkan/swapchain.h +++ b/include/QF/Vulkan/swapchain.h @@ -13,5 +13,6 @@ typedef struct qfv_swapchain_s { struct vulkan_ctx_s; qfv_swapchain_t *QFV_CreateSwapchain (struct vulkan_ctx_s *ctx, VkSwapchainKHR old_swapchain); +void QFV_DestroySwapchain (qfv_swapchain_t *swapchain); #endif//__QF_Vulkan_swapchain_h diff --git a/libs/video/renderer/r_init.c b/libs/video/renderer/r_init.c index 330d0d76d..df2392a6b 100644 --- a/libs/video/renderer/r_init.c +++ b/libs/video/renderer/r_init.c @@ -63,6 +63,14 @@ vid_render_funcs_t *r_funcs; static U void (*const r_progs_init)(struct progs_s *) = R_Progs_Init; #undef U +static void +R_shutdown (void) +{ + if (vidrendmodule->functions->general->p_Shutdown) { + vidrendmodule->functions->general->p_Shutdown (); + } +} + VISIBLE void R_LoadModule (vid_internal_t *vid_internal) { @@ -80,6 +88,7 @@ R_LoadModule (vid_internal_t *vid_internal) r_data->vid->vid_internal = vid_internal; vidrendmodule->functions->general->p_Init (); + Sys_RegisterShutdown (R_shutdown); } VISIBLE void diff --git a/libs/video/renderer/vulkan/device.c b/libs/video/renderer/vulkan/device.c index 36b81b025..736b5e915 100644 --- a/libs/video/renderer/vulkan/device.c +++ b/libs/video/renderer/vulkan/device.c @@ -133,9 +133,6 @@ QFV_CreateDevice (vulkan_ctx_t *ctx, const char **extensions) { uint32_t nlay = 1; // ensure alloca doesn't see 0 and terminated uint32_t next = count_strings (extensions) + 1; // ensure terminated - //if (vulkan_use_validation->int_val) { - // nlay += count_strings (vulkanValidationLayers); - //} const char **lay = alloca (nlay * sizeof (const char *)); const char **ext = alloca (next * sizeof (const char *)); // ensure there are null pointers so merge_strings can act as append @@ -144,9 +141,6 @@ QFV_CreateDevice (vulkan_ctx_t *ctx, const char **extensions) memset (lay, 0, nlay-- * sizeof (const char *)); memset (ext, 0, next-- * sizeof (const char *)); merge_strings (ext, extensions, 0); - //if (vulkan_use_validation->int_val) { - // merge_strings (lay, lay, vulkanValidationLayers); - //} qfv_instance_t *inst = ctx->instance; VkInstance instance = inst->instance; @@ -160,9 +154,6 @@ QFV_CreateDevice (vulkan_ctx_t *ctx, const char **extensions) for (uint32_t i = 0; i < numDevices; i++) { VkPhysicalDevice physdev = devices[i]; /* - if (!Vulkan_LayersSupported (phys->layers, phys->numLayers, lay)) { - continue; - } if (!Vulkan_ExtensionsSupported (phys->extensions, phys->numExtensions, ext)) { continue; @@ -209,3 +200,11 @@ QFV_CreateDevice (vulkan_ctx_t *ctx, const char **extensions) } return 0; } + +void +QFV_DestroyDevice (qfv_device_t *device) +{ + device->funcs->vkDestroyDevice (device->dev, 0); + del_strset (device->enabled_extensions); + free (device); +} diff --git a/libs/video/renderer/vulkan/swapchain.c b/libs/video/renderer/vulkan/swapchain.c index 91f8280c9..2707676d6 100644 --- a/libs/video/renderer/vulkan/swapchain.c +++ b/libs/video/renderer/vulkan/swapchain.c @@ -146,3 +146,11 @@ QFV_CreateSwapchain (vulkan_ctx_t *ctx, VkSwapchainKHR old_swapchain) sc->images); return sc; } + +void +QFV_DestroySwapchain (qfv_swapchain_t *swapchain) +{ + swapchain->funcs->vkDestroySwapchainKHR (swapchain->dev, + swapchain->swapchain, 0); + free (swapchain); +} diff --git a/libs/video/renderer/vulkan/vulkan_vid_common.c b/libs/video/renderer/vulkan/vulkan_vid_common.c index 70890ab7a..ed5369c9c 100644 --- a/libs/video/renderer/vulkan/vulkan_vid_common.c +++ b/libs/video/renderer/vulkan/vulkan_vid_common.c @@ -116,6 +116,8 @@ Vulkan_Init_Common (vulkan_ctx_t *ctx) void Vulkan_Shutdown_Common (vulkan_ctx_t *ctx) { + Sys_Printf ("are we here?\n"); + QFV_DestroyDevice (ctx->device); QFV_DestroyInstance (ctx->instance); ctx->instance = 0; ctx->unload_vulkan (ctx);