From 3f7cbae4d0913c401a0f4eb38e615c4cd1e130c7 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 7 May 2022 09:56:46 +0900 Subject: [PATCH] [vulkan] Rework builtin plist handing The plists can now be accessed by name and the forward render pass config is available (but not used, or tested beyond syntax). I was going to have the IQM pipeline spec separate but ran into limitations in the system (which needs a lot of polish, really). --- libs/video/renderer/Makemodule.am | 13 +-- .../video/renderer/vulkan/vulkan_vid_common.c | 82 +++++++++++++++++-- 2 files changed, 81 insertions(+), 14 deletions(-) diff --git a/libs/video/renderer/Makemodule.am b/libs/video/renderer/Makemodule.am index 48b4f13d9..fd1496752 100644 --- a/libs/video/renderer/Makemodule.am +++ b/libs/video/renderer/Makemodule.am @@ -181,8 +181,10 @@ libs_video_renderer_librender_sw_la_SOURCES = \ pipeline_src = libs/video/renderer/vulkan/qfpipeline.plist pipeline_gen = libs/video/renderer/vulkan/qfpipeline.plc -renderpass_src = libs/video/renderer/vulkan/deferred.plist -renderpass_gen = libs/video/renderer/vulkan/deferred.plc +deferred_src = libs/video/renderer/vulkan/deferred.plist +deferred_gen = libs/video/renderer/vulkan/deferred.plc +forward_src = libs/video/renderer/vulkan/forward.plist +forward_gen = libs/video/renderer/vulkan/forward.plc video_renderer_vulkan_libs = \ libs/video/renderer/librender_vulkan.la \ @@ -232,7 +234,7 @@ libs/video/renderer/vulkan/vkparse.lo: libs/video/renderer/vulkan/vkparse.c $(vk libs/video/renderer/vulkan/shader.lo: libs/video/renderer/vulkan/shader.c $(vkshader_c) -libs/video/renderer/vulkan/vulkan_vid_common.lo: libs/video/renderer/vulkan/vulkan_vid_common.c $(vkparse_src) $(pipeline_gen) ${renderpass_gen} +libs/video/renderer/vulkan/vulkan_vid_common.lo: libs/video/renderer/vulkan/vulkan_vid_common.c $(vkparse_src) $(pipeline_gen) ${deferred_gen} $(forward_gen) qwaq_cmd = $(top_builddir)/ruamoko/qwaq/qwaq-cmd$(EXEEXT) @@ -441,8 +443,9 @@ BUILT_SOURCES += $(shader_gen) # libs/video/renderer/vulkan/pushcolor.frag.spv EXTRA_DIST += \ - libs/video/renderer/vulkan/deferred.plist \ - libs/video/renderer/vulkan/qfpipeline.plist \ + $(deferred_src) \ + $(forward_src) \ + $(pipeline_src) \ libs/video/renderer/vulkan/vkparse.plist \ libs/video/renderer/vulkan/vkparse.h \ libs/video/renderer/vulkan/shader/alias.frag \ diff --git a/libs/video/renderer/vulkan/vulkan_vid_common.c b/libs/video/renderer/vulkan/vulkan_vid_common.c index 6eccebcd7..0eaccc253 100644 --- a/libs/video/renderer/vulkan/vulkan_vid_common.c +++ b/libs/video/renderer/vulkan/vulkan_vid_common.c @@ -83,13 +83,23 @@ #include "libs/video/renderer/vulkan/vkparse.hinc" -static const char quakeforge_pipeline[] = +static exprsym_t builtin_plist_syms[] = { + { .name = "qfpipeline", + .value = (void *) #include "libs/video/renderer/vulkan/qfpipeline.plc" -; - -static const char quakeforge_renderpass[] = + }, + { .name = "deferred", + .value = (void *) #include "libs/video/renderer/vulkan/deferred.plc" -; + }, + { .name = "forward", + .value = (void *) +#include "libs/video/renderer/vulkan/forward.plc" + }, + {} +}; +static plitem_t **builtin_plists; +static exprtab_t builtin_configs = { .symbols = builtin_plist_syms }; int vulkan_frame_count; static cvar_t vulkan_frame_count_cvar = { @@ -298,12 +308,67 @@ Vulkan_CreateSwapchain (vulkan_ctx_t *ctx) } } +static void +build_configs (vulkan_ctx_t *ctx) +{ + int num_plists = 0; + for (exprsym_t *sym = builtin_plist_syms; sym->name; sym++) { + num_plists++; + } + builtin_plists = malloc (num_plists * sizeof (plitem_t *)); + num_plists = 0; + for (exprsym_t *sym = builtin_plist_syms; sym->name; sym++) { + plitem_t *item = PL_GetPropertyList (sym->value, &ctx->hashlinks); + if (!item) { + // Syntax errors in the compiled-in plists are unrecoverable + Sys_Error ("Error parsing plist for %s", sym->name); + } + builtin_plists[num_plists] = item; + sym->value = &builtin_plists[num_plists]; + sym->type = &cexpr_plitem; + num_plists++; + } + exprctx_t ectx = { .hashlinks = &ctx->hashlinks }; + cexpr_init_symtab (&builtin_configs, &ectx); +} + +static plitem_t * +get_builtin_config (vulkan_ctx_t *ctx, const char *name) +{ + if (!builtin_configs.tab) { + build_configs (ctx); + } + + plitem_t *config = 0; + exprval_t result = { .type = &cexpr_plitem, .value = &config }; + exprctx_t ectx = { + .result = &result, + .symtab = &builtin_configs, + .memsuper = new_memsuper (), + .hashlinks = &ctx->hashlinks, + .messages = PL_NewArray (), + }; + if (cexpr_eval_string (name, &ectx)) { + dstring_t *msg = dstring_newstr (); + + for (int i = 0; i < PL_A_NumObjects (ectx.messages); i++) { + dasprintf (msg, "%s\n", + PL_String (PL_ObjectAtIndex (ectx.messages, i))); + } + Sys_Printf ("%s", msg->str); + dstring_delete (msg); + config = 0; + } + PL_Free (ectx.messages); + delete_memsuper (ectx.memsuper); + return config; +} + static plitem_t * qfv_load_pipeline (vulkan_ctx_t *ctx, const char *name) { if (!ctx->pipelineDef) { - ctx->pipelineDef = PL_GetPropertyList (quakeforge_pipeline, - &ctx->hashlinks); + ctx->pipelineDef = get_builtin_config (ctx, "qfpipeline"); } plitem_t *item = ctx->pipelineDef; @@ -319,8 +384,7 @@ static plitem_t * qfv_load_renderpass (vulkan_ctx_t *ctx, qfv_renderpass_t *rp, const char *name) { if (!rp->renderpassDef) { - rp->renderpassDef = PL_GetPropertyList (quakeforge_renderpass, - &ctx->hashlinks); + rp->renderpassDef = get_builtin_config (ctx, "deferred"); } plitem_t *item = rp->renderpassDef;