From 3de39f54088aa745ed6ee616c8e36a76b1d9cafb Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 21 Jun 2023 17:58:15 +0900 Subject: [PATCH] [vulkan] Destroy frame buffers on shutdown With this, the new render system, though not doing anything useful, at least passes validation. --- include/QF/Vulkan/render.h | 1 + libs/video/renderer/vulkan/render.c | 51 +++++++++++----------- libs/video/renderer/vulkan/vulkan_output.c | 9 ++++ 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/include/QF/Vulkan/render.h b/include/QF/Vulkan/render.h index 66114798f..c8c843988 100644 --- a/include/QF/Vulkan/render.h +++ b/include/QF/Vulkan/render.h @@ -384,6 +384,7 @@ void QFV_Render_AddTasks (struct vulkan_ctx_s *ctx, exprsym_t *task_sys); void QFV_CreateFramebuffer (struct vulkan_ctx_s *ctx, qfv_renderpass_t *rp); qfv_step_t *QFV_GetStep (const exprval_t *param, qfv_job_t *job); +qfv_step_t *QFV_FindStep (const char *step, qfv_job_t *job) __attribute__((pure)); #endif//__QFCC__ #endif//__QF_Vulkan_render_h diff --git a/libs/video/renderer/vulkan/render.c b/libs/video/renderer/vulkan/render.c index 45ba7a887..9c7e352f1 100644 --- a/libs/video/renderer/vulkan/render.c +++ b/libs/video/renderer/vulkan/render.c @@ -280,24 +280,6 @@ QFV_RunRenderJob (vulkan_ctx_t *ctx) dfunc->vkQueuePresentKHR (queue->queue, &presentInfo); } -#if 0 -void -QFV_DestroyFramebuffer (vulkan_ctx_t *ctx) -{ - qfv_device_t *device = ctx->device; - qfv_devfuncs_t *dfunc = device->funcs; - __auto_type rctx = ctx->render_context; - __auto_type job = rctx->job; - __auto_type rp = &job->renderpasses[0]; - - if (rp->beginInfo.framebuffer) { - VkFramebuffer framebuffer = rp->beginInfo.framebuffer; - rp->beginInfo.framebuffer = 0; - dfunc->vkDestroyFramebuffer (device->dev, framebuffer, 0); - } -} -#endif - static VkImageView __attribute__((pure)) find_imageview (qfv_reference_t *ref, qfv_renderctx_t *rctx) { @@ -485,6 +467,18 @@ QFV_Render_Shutdown (vulkan_ctx_t *ctx) QFV_DestroyResource (ctx->device, job->resources); free (job->resources); } + for (uint32_t i = 0; i < job->num_steps; i++) { + if (job->steps[i].render) { + auto render = job->steps[i].render; + for (uint32_t j = 0; j < render->num_renderpasses; j++) { + auto bi = &render->renderpasses[j].beginInfo; + if (bi->framebuffer) { + dfunc->vkDestroyFramebuffer (device->dev, + bi->framebuffer, 0); + } + } + } + } job->command_pool = 0; DARRAY_CLEAR (&job->commands); free (rctx->job); @@ -525,6 +519,18 @@ QFV_Render_AddTasks (vulkan_ctx_t *ctx, exprsym_t *task_syms) } } +qfv_step_t * +QFV_FindStep (const char *name, qfv_job_t *job) +{ + for (uint32_t i = 0; i < job->num_steps; i++) { + auto step = &job->steps[i]; + if (!strcmp (step->label.name, name)) { + return step; + } + } + return 0; +} + qfv_step_t * QFV_GetStep (const exprval_t *param, qfv_job_t *job) { @@ -540,14 +546,7 @@ QFV_GetStep (const exprval_t *param, qfv_job_t *job) } auto name = *(const char **)stepref->value; stepref->type = &cexpr_voidptr; - *(void **)stepref->value = 0; - for (uint32_t i = 0; i < job->num_steps; i++) { - auto step = &job->steps[i]; - if (!strcmp (step->label.name, name)) { - *(void **)stepref->value = step; - break; - } - } + *(qfv_step_t **)stepref->value = QFV_FindStep (name, job); } return *(qfv_step_t **)stepref->value; } diff --git a/libs/video/renderer/vulkan/vulkan_output.c b/libs/video/renderer/vulkan/vulkan_output.c index 669997740..cc5058d20 100644 --- a/libs/video/renderer/vulkan/vulkan_output.c +++ b/libs/video/renderer/vulkan/vulkan_output.c @@ -442,6 +442,15 @@ Vulkan_Output_Shutdown (vulkan_ctx_t *ctx) qfv_devfuncs_t *dfunc = device->funcs; outputctx_t *octx = ctx->output_context; + for (uint32_t i = 0; i < ctx->swapchain->imageViews->size; i++) { + dfunc->vkDestroyFramebuffer (device->dev, octx->framebuffers[i], 0); + } + free (octx->framebuffers); + auto step = QFV_FindStep ("output", ctx->render_context->job); + auto render = step->render; + auto rp = &render->renderpasses[0]; + rp->beginInfo.framebuffer = 0; + dfunc->vkDestroyPipeline (device->dev, octx->output, 0); dfunc->vkDestroyPipeline (device->dev, octx->waterwarp, 0); dfunc->vkDestroyPipeline (device->dev, octx->fisheye, 0);