From 2c3b89f722bb49eaecdfa885867bd2698560653a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 13 Feb 2023 01:43:17 +0900 Subject: [PATCH] [vulkan] Implement task function parsing This just sets up the memory block and cexpr descriptors for the parameters, parameter parsing is separate (and next). The parameters are aligned to their size. --- include/QF/Vulkan/render.h | 7 +- libs/video/renderer/vulkan/render.c | 20 +++++- libs/video/renderer/vulkan/rp_main_def.plist | 6 +- libs/video/renderer/vulkan/vkparse.c | 74 +++++++++++++++++--- libs/video/renderer/vulkan/vkparse.h | 4 +- libs/video/renderer/vulkan/vkparse.plist | 4 +- 6 files changed, 98 insertions(+), 17 deletions(-) diff --git a/include/QF/Vulkan/render.h b/include/QF/Vulkan/render.h index f71c868b9..9c5f35ef6 100644 --- a/include/QF/Vulkan/render.h +++ b/include/QF/Vulkan/render.h @@ -67,7 +67,8 @@ typedef struct qfv_attachmentinfo_s { typedef struct qfv_taskinfo_s { struct exprfunc_s *func; - void *params; + const struct exprval_s **params; + void *param_data; } qfv_taskinfo_t; typedef struct qfv_attachmentrefinfo_s { @@ -132,6 +133,10 @@ typedef struct qfv_renderinfo_s { qfv_renderpassinfo_t *renderpasses; } qfv_renderinfo_t; +typedef struct qfv_renderctx_s { + struct exprtab_s *task_functions; +} qfv_renderctx_t; + typedef struct qfv_label_s { vec4f_t color; const char *name; diff --git a/libs/video/renderer/vulkan/render.c b/libs/video/renderer/vulkan/render.c index 3bd36255b..eb5311c86 100644 --- a/libs/video/renderer/vulkan/render.c +++ b/libs/video/renderer/vulkan/render.c @@ -38,6 +38,7 @@ # include #endif +#include "QF/hash.h" #include "QF/Vulkan/command.h" #include "QF/Vulkan/debug.h" #include "QF/Vulkan/device.h" @@ -124,10 +125,27 @@ QFV_RunRenderPass (qfv_renderpass_t_ *rp, vulkan_ctx_t *ctx) QFV_CmdEndLabel (device, cmd); } +static exprsym_t qfv_renderpass_task_symbols[] = { + + {} +}; + void QFV_LoadRenderPass (vulkan_ctx_t *ctx) { + + exprtab_t task_tab = { qfv_renderpass_task_symbols, 0 }; + exprctx_t ectx = { + .symtab = &task_tab, + .hashctx = &ctx->script_context->hashctx, + }; + cexpr_init_symtab (&task_tab, &ectx); + + qfv_renderctx_t rctx = { .task_functions = &task_tab }; + plitem_t *item = Vulkan_GetConfig (ctx, "main_def"); - __auto_type ri = QFV_ParseRenderInfo (ctx, item); + __auto_type ri = QFV_ParseRenderInfo (ctx, item, &rctx); printf ("%p\n", ri); + + Hash_DelTable (task_tab.tab); } diff --git a/libs/video/renderer/vulkan/rp_main_def.plist b/libs/video/renderer/vulkan/rp_main_def.plist index 2419ed113..7890652bc 100644 --- a/libs/video/renderer/vulkan/rp_main_def.plist +++ b/libs/video/renderer/vulkan/rp_main_def.plist @@ -366,19 +366,19 @@ renderpasses = { color = $color.compose; pipeline = compose; tasks = ( - { func = "lights_draw"; }, + { func = "compose_draw"; }, ); }; }; }; }; }; - deferred_cube = { +/* deferred_cube = { @inherit = $renderpasses.deferred; @next = (VkRenderPassMultiviewCreateInfo, { viewMasks = (0x3fu, 0x3fu, 0x3fu, 0x3fu, 0x3fu); viewOffsets = ( 0, 0, 0, 0, 0); }); - }; + };*/ }; }; diff --git a/libs/video/renderer/vulkan/vkparse.c b/libs/video/renderer/vulkan/vkparse.c index 6c7fa711a..e0ce60b6f 100644 --- a/libs/video/renderer/vulkan/vkparse.c +++ b/libs/video/renderer/vulkan/vkparse.c @@ -520,7 +520,7 @@ parse_inherit (const plfield_t *field, const plitem_t *item, ectx.result = &result; ectx.item = item; const char *inheritstr = PL_String (item); - Sys_MaskPrintf (SYS_vulkan_parse, "parse_inherit: %s\n", inheritstr); + //Sys_MaskPrintf (SYS_vulkan_parse, "parse_inherit: %s\n", inheritstr); int ret = !cexpr_eval_string (inheritstr, &ectx); if (ret) { ret = PL_ParseStruct (field->data, inheritItem, data, messages, @@ -566,10 +566,10 @@ parse_RGBA (const plitem_t *item, void **data, ectx.result = &result; ectx.item = item; const char *valstr = PL_String (item); - Sys_MaskPrintf (SYS_vulkan_parse, "parse_RGBA: %s\n", valstr); + //Sys_MaskPrintf (SYS_vulkan_parse, "parse_RGBA: %s\n", valstr); ret = !cexpr_eval_string (valstr, &ectx); - Sys_MaskPrintf (SYS_vulkan_parse, " "VEC4F_FMT"\n", - VEC4_EXP (*(vec4f_t *)data[0])); + //Sys_MaskPrintf (SYS_vulkan_parse, " "VEC4F_FMT"\n", + // VEC4_EXP (*(vec4f_t *)data[0])); return ret; } @@ -1085,8 +1085,58 @@ static int parse_task_function (const plitem_t *item, void **data, plitem_t *messages, parsectx_t *pctx) { - PL_Message (messages, item, "parse_task_function: not implemented"); - return 0; + qfv_renderctx_t *rctx = pctx->data; + const char *fname = PL_String (item); + exprsym_t *fsym = Hash_Find (rctx->task_functions->tab, fname); + + if (!fsym) { + PL_Message (messages, item, "undefined task function %s", fname); + return 0; + } + if (fsym->type != &cexpr_function) { + PL_Message (messages, item, "not a function type %s", fname); + return 0; + } + exprfunc_t *func; + for (func = fsym->value; func->func; func++) { + if (!func->result) { + break; + } + } + if (!func->func) { + PL_Message (messages, item, "%s does not have a void implementation", + fname); + return 0; + } + size_t size = func->num_params * sizeof (exprval_t); + size += func->num_params * sizeof (exprval_t *); + size_t base = size; + for (int i = 0; i < func->num_params; i++) { + exprtype_t *type = func->param_types[i]; + size = ((size + type->size - 1) & ~(type->size - 1)); + if (i == 0) { + base = size; + } + } + exprval_t **param_ptrs = vkparse_alloc (pctx, size); + exprval_t *params = (exprval_t *) ¶m_ptrs[func->num_params]; + byte *param_data = (byte *) param_ptrs + base; + memset (params, 0, size); + size_t offs = 0; + for (int i = 0; i < func->num_params; i++) { + exprtype_t *type = func->param_types[i]; + param_ptrs[i] = ¶ms[i]; + params[i] = (exprval_t) { + .type = type, + .value = param_data + offs, + }; + offs = ((offs + type->size - 1) & ~(type->size - 1)); + offs += type->size; + } + *(exprfunc_t **) data[0] = func; + *(exprval_t ***) data[1] = param_ptrs; + *(void **) data[2] = param_data; + return 1; } static int @@ -2127,7 +2177,7 @@ Vulkan_CreateDescriptorSetLayout(vulkan_ctx_t *ctx, const char *name) } qfv_renderinfo_t * -QFV_ParseRenderInfo (vulkan_ctx_t *ctx, plitem_t *item) +QFV_ParseRenderInfo (vulkan_ctx_t *ctx, plitem_t *item, qfv_renderctx_t *rctx) { memsuper_t *memsuper = new_memsuper (); qfv_renderinfo_t *ri = cmemalloc (memsuper, sizeof (qfv_renderinfo_t)); @@ -2139,7 +2189,12 @@ QFV_ParseRenderInfo (vulkan_ctx_t *ctx, plitem_t *item) scriptctx_t *sctx = ctx->script_context; plitem_t *messages = PL_NewArray (); exprctx_t exprctx = { .symtab = &root_symtab }; - parsectx_t parsectx = { &exprctx, ctx, properties }; + parsectx_t parsectx = { + .ectx = &exprctx, + .vctx = ctx, + .properties = properties, + .data = rctx + }; plitem_t *pl_items[num_keys + 3]; exprsym_t var_syms[num_keys + 7 + 1]; exprtab_t vars_tab = { var_syms, 0 }; @@ -2208,8 +2263,9 @@ QFV_ParseRenderInfo (vulkan_ctx_t *ctx, plitem_t *item) } Hash_DelTable (vars_tab.tab); PL_Free (messages); - if (!ri) { + if (!ret) { delete_memsuper (memsuper); + ri = 0; } return ri; diff --git a/libs/video/renderer/vulkan/vkparse.h b/libs/video/renderer/vulkan/vkparse.h index 8b429fdaf..d92429332 100644 --- a/libs/video/renderer/vulkan/vkparse.h +++ b/libs/video/renderer/vulkan/vkparse.h @@ -77,6 +77,8 @@ int QFV_ParseRGBA (vulkan_ctx_t *ctx, float *rgba, plitem_t *plist, plitem_t *properties); int QFV_ParseOutput (vulkan_ctx_t *ctx, qfv_output_t *output, plitem_t *plist, plitem_t *properties); +struct qfv_renderctx_s; struct qfv_renderinfo_s *QFV_ParseRenderInfo (vulkan_ctx_t *ctx, - plitem_t *item); + plitem_t *item, + struct qfv_renderctx_s *rctx); #endif//__vkparse_h diff --git a/libs/video/renderer/vulkan/vkparse.plist b/libs/video/renderer/vulkan/vkparse.plist index d554e8f7c..49fc3ca6a 100644 --- a/libs/video/renderer/vulkan/vkparse.plist +++ b/libs/video/renderer/vulkan/vkparse.plist @@ -427,11 +427,11 @@ .name = qfv_taskinfo_t; func = { type = (custom, QFString, parse_task_function); - fields = (func); + fields = (func, params, param_data); }; params = { type = (custom, QFArray, parse_task_params); - fields = (params, func); + fields = (func, params, param_data); }; }; qfv_attachmentrefinfo_s = {