[vulkan] Clear out the resource tables on shutdown

This would take care of undestroyed resources if there wasn't a problem
with invalid memory use. Not sure what's going on just yet.
This commit is contained in:
Bill Currie 2021-01-05 17:48:00 +09:00
parent dc704a9384
commit 3cf8a336a8
2 changed files with 22 additions and 3 deletions

View file

@ -405,7 +405,9 @@ setLayout_free (void *hr, void *_ctx)
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
dfunc->vkDestroyDescriptorSetLayout (device->dev, layout, 0);
if (layout) {
dfunc->vkDestroyDescriptorSetLayout (device->dev, layout, 0);
}
handleref_free (handleref, ctx);
}
@ -418,7 +420,9 @@ shaderModule_free (void *hr, void *_ctx)
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
dfunc->vkDestroyShaderModule (device->dev, module, 0);
if (module) {
dfunc->vkDestroyShaderModule (device->dev, module, 0);
}
handleref_free (handleref, ctx);
}
@ -431,7 +435,9 @@ pipelineLayout_free (void *hr, void *_ctx)
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
dfunc->vkDestroyPipelineLayout (device->dev, layout, 0);
if (layout) {
dfunc->vkDestroyPipelineLayout (device->dev, layout, 0);
};
handleref_free (handleref, ctx);
}

View file

@ -43,6 +43,7 @@
#include "QF/cmem.h"
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/hash.h"
#include "QF/input.h"
#include "QF/mathlib.h"
#include "QF/qargs.h"
@ -144,6 +145,15 @@ Vulkan_Init_Common (vulkan_ctx_t *ctx)
ctx->instance = QFV_CreateInstance (ctx, PACKAGE_STRING, 0x000702ff, 0, instance_extensions);//FIXME version
}
static void
clear_table (hashtab_t **table)
{
if (*table) {
Hash_DelTable (*table);
*table = 0;
}
}
void
Vulkan_Shutdown_Common (vulkan_ctx_t *ctx)
{
@ -156,6 +166,9 @@ Vulkan_Shutdown_Common (vulkan_ctx_t *ctx)
if (ctx->swapchain) {
QFV_DestroySwapchain (ctx->swapchain);
}
clear_table (&ctx->pipelineLayouts);
clear_table (&ctx->setLayouts);
clear_table (&ctx->shaderModules);
ctx->instance->funcs->vkDestroySurfaceKHR (ctx->instance->instance,
ctx->surface, 0);
if (ctx->device) {