Ensure vulkan gets shut down

This commit is contained in:
Bill Currie 2019-07-13 00:36:21 +09:00
parent 4e4d1b99b4
commit 1eafc33052
7 changed files with 37 additions and 11 deletions

View file

@ -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,
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

View file

@ -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

View file

@ -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

View file

@ -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

View file

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

View file

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

View file

@ -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);