diff --git a/libs/video/renderer/vulkan/vkparse.c b/libs/video/renderer/vulkan/vkparse.c index fbba8238b..cd5e98502 100644 --- a/libs/video/renderer/vulkan/vkparse.c +++ b/libs/video/renderer/vulkan/vkparse.c @@ -477,6 +477,21 @@ descriptorPool_free (void *hr, void *_ctx) handleref_free (handleref, ctx); } +static void +sampler_free (void *hr, void *_ctx) +{ + __auto_type handleref = (handleref_t *) hr; + __auto_type sampler = (VkSampler) handleref->handle; + __auto_type ctx = (vulkan_ctx_t *) _ctx; + qfv_device_t *device = ctx->device; + qfv_devfuncs_t *dfunc = device->funcs; + + if (sampler) { + dfunc->vkDestroySampler (device->dev, sampler, 0); + }; + handleref_free (handleref, ctx); +} + static hashtab_t *enum_symtab; static int @@ -560,10 +575,23 @@ static plfield_t renderpass_fields[] = { {} }; +static hashtab_t * +handlref_symtab (void (*free_func)(void*,void*), vulkan_ctx_t *ctx) +{ + return Hash_NewTable (23, handleref_getkey, free_func, + ctx, &ctx->hashlinks); +} + void QFV_ParseResources (vulkan_ctx_t *ctx, plitem_t *pipelinedef) { plitem_t *messages = PL_NewArray (); + exprsym_t var_syms[] = { + {"swapchain", &qfv_swapchain_t_type, ctx->swapchain}, + {"msaaSamples", &VkSampleCountFlagBits_type, &ctx->msaaSamples}, + {} + }; + exprtab_t vars_tab = { var_syms, 0 }; exprctx_t exprctx = {}; parsectx_t parsectx = { &exprctx, ctx }; int ret = 1; @@ -571,19 +599,15 @@ QFV_ParseResources (vulkan_ctx_t *ctx, plitem_t *pipelinedef) exprctx.memsuper = new_memsuper (); exprctx.messages = messages; exprctx.hashlinks = &ctx->hashlinks; + exprctx.external_variables = &vars_tab; + cexpr_init_symtab (&vars_tab, &exprctx); if (!ctx->setLayouts) { - ctx->shaderModules = Hash_NewTable (23, handleref_getkey, - shaderModule_free, - ctx, &ctx->hashlinks); - ctx->setLayouts = Hash_NewTable (23, handleref_getkey, setLayout_free, - ctx, &ctx->hashlinks); - ctx->pipelineLayouts = Hash_NewTable (23, handleref_getkey, - pipelineLayout_free, - ctx, &ctx->hashlinks); - ctx->descriptorPools = Hash_NewTable (23, handleref_getkey, - descriptorPool_free, - ctx, &ctx->hashlinks); + ctx->shaderModules = handlref_symtab (shaderModule_free, ctx); + ctx->setLayouts = handlref_symtab (setLayout_free, ctx); + ctx->pipelineLayouts = handlref_symtab (pipelineLayout_free, ctx); + ctx->descriptorPools = handlref_symtab (descriptorPool_free, ctx); + ctx->samplers = handlref_symtab (sampler_free, ctx); } for (parseres_t *res = parse_resources; res->name; res++) { @@ -646,11 +670,10 @@ QFV_ParseRenderPass (vulkan_ctx_t *ctx, plitem_t *plist) exprctx_t exprctx = {}; parsectx_t parsectx = { &exprctx, ctx }; - exprctx.external_variables = &vars_tab; exprctx.memsuper = new_memsuper (); exprctx.messages = messages; exprctx.hashlinks = &ctx->hashlinks; - + exprctx.external_variables = &vars_tab; cexpr_init_symtab (&vars_tab, &exprctx); if (!PL_ParseStruct (renderpass_fields, plist, &renderpass_data, diff --git a/libs/video/renderer/vulkan/vkparse.h b/libs/video/renderer/vulkan/vkparse.h index 394cd296d..75dd8fe9d 100644 --- a/libs/video/renderer/vulkan/vkparse.h +++ b/libs/video/renderer/vulkan/vkparse.h @@ -7,6 +7,7 @@ typedef struct parsectx_s { } parsectx_t; #include "QF/cexpr.h" +#include "QF/qfplist.h" #include "QF/Vulkan/renderpass.h" #ifdef vkparse_internal #include "libs/video/renderer/vulkan/vkparse.hinc" diff --git a/libs/video/renderer/vulkan/vkparse.plist b/libs/video/renderer/vulkan/vkparse.plist index fc406b4c4..edf68541e 100644 --- a/libs/video/renderer/vulkan/vkparse.plist +++ b/libs/video/renderer/vulkan/vkparse.plist @@ -19,6 +19,7 @@ VkPipelineLayoutCreateInfo, VkGraphicsPipelineCreateInfo, VkDescriptorPoolCreateInfo, + VkSamplerCreateInfo, ); handles = { VkShaderModule = { @@ -41,6 +42,11 @@ class = "pipeline layout"; create = vkCreatePipelineLayout; }; + VkSampler = { + symtab = samplers; + class = "sampler"; + create = vkCreateSampler; + }; }; resources = ( { @@ -64,6 +70,20 @@ type = handleref_t; table = pipelineLayouts; }, + { + name = descriptorPools; + parse_type = QFDictionary; + parser = parse_VkDescriptorPool_handleref; + type = handleref_t; + table = descriptorPools; + }, + { + name = samplers; + parse_type = QFDictionary; + parser = parse_VkSampler_handleref; + type = handleref_t; + table = samplers; + }, ); parse = { VkSubpassDescription = { diff --git a/libs/video/renderer/vulkan/vulkan_vid_common.c b/libs/video/renderer/vulkan/vulkan_vid_common.c index 8d0aa4870..3f701e27a 100644 --- a/libs/video/renderer/vulkan/vulkan_vid_common.c +++ b/libs/video/renderer/vulkan/vulkan_vid_common.c @@ -176,6 +176,8 @@ Vulkan_Shutdown_Common (vulkan_ctx_t *ctx) clear_table (&ctx->pipelineLayouts); clear_table (&ctx->setLayouts); clear_table (&ctx->shaderModules); + clear_table (&ctx->descriptorPools); + clear_table (&ctx->samplers); if (ctx->device) { QFV_DestroyDevice (ctx->device); }