From e4f75791ce273bc74a03828e2207fed1891736f2 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 4 Jan 2021 17:26:39 +0900 Subject: [PATCH] [vulkan] Clean up some tangled dependencies Dependencies on vkparse.hinc were spreading through the code which I didn't want as that removes a lot of the automation from the automake files. This keeps all parser code internal to vkparse.c's scope, and any accesses required for enum and struct (not yet) definitions can be fetched by name. --- include/QF/Vulkan/shader.h | 3 -- libs/video/renderer/vulkan/descriptor.c | 1 - libs/video/renderer/vulkan/shader.c | 16 ------ libs/video/renderer/vulkan/vkgen/vkenum.h | 1 + libs/video/renderer/vulkan/vkgen/vkenum.r | 6 +++ libs/video/renderer/vulkan/vkgen/vkgen.r | 1 + libs/video/renderer/vulkan/vkgen/vkstruct.h | 1 + libs/video/renderer/vulkan/vkgen/vkstruct.r | 4 ++ libs/video/renderer/vulkan/vkparse.c | 52 +++++++++++++++---- libs/video/renderer/vulkan/vkparse.h | 3 ++ .../video/renderer/vulkan/vulkan_vid_common.c | 5 +- 11 files changed, 62 insertions(+), 31 deletions(-) diff --git a/include/QF/Vulkan/shader.h b/include/QF/Vulkan/shader.h index b13f6a618..41b38a862 100644 --- a/include/QF/Vulkan/shader.h +++ b/include/QF/Vulkan/shader.h @@ -15,8 +15,5 @@ VkShaderModule QFV_FindShaderModule (struct vulkan_ctx_s *ctx, void QFV_RegisterShaderModule (struct vulkan_ctx_s *ctx, const char *name, VkShaderModule module); void QFV_DeregisterShaderModule (struct vulkan_ctx_s *ctx, const char *name); -int parse_VkShaderModule (const struct plitem_s *item, void **data, - struct plitem_s *messages, - struct parsectx_s *context); #endif//__QF_Vulkan_shader_h diff --git a/libs/video/renderer/vulkan/descriptor.c b/libs/video/renderer/vulkan/descriptor.c index 23c1a0d50..dc7cc6fa4 100644 --- a/libs/video/renderer/vulkan/descriptor.c +++ b/libs/video/renderer/vulkan/descriptor.c @@ -44,7 +44,6 @@ #include "QF/hash.h" #include "QF/input.h" #include "QF/mathlib.h" -#include "QF/qargs.h" #include "QF/quakefs.h" #include "QF/sys.h" #include "QF/va.h" diff --git a/libs/video/renderer/vulkan/shader.c b/libs/video/renderer/vulkan/shader.c index 5ee89ca25..e55833782 100644 --- a/libs/video/renderer/vulkan/shader.c +++ b/libs/video/renderer/vulkan/shader.c @@ -53,7 +53,6 @@ #include "QF/Vulkan/shader.h" #include "vid_vulkan.h" -#include "vkparse.h" static #include "libs/video/renderer/vulkan/passthrough.vert.spvc" @@ -212,18 +211,3 @@ QFV_DeregisterShaderModule (vulkan_ctx_t *ctx, const char *name) } Hash_Free (ctx->shadermodules, Hash_Del (ctx->shadermodules, name)); } - -int -parse_VkShaderModule (const plitem_t *item, void **data, - plitem_t *messages, parsectx_t *context) -{ - vulkan_ctx_t *ctx = context->vctx; - const char *name = PL_String (item); - __auto_type mptr = (VkShaderModule *)data[0]; - VkShaderModule module = QFV_FindShaderModule (ctx, name); - if (module) { - *mptr = module; - return 1; - } - return 0; -} diff --git a/libs/video/renderer/vulkan/vkgen/vkenum.h b/libs/video/renderer/vulkan/vkgen/vkenum.h index 4df770b92..5577b8a23 100644 --- a/libs/video/renderer/vulkan/vkgen/vkenum.h +++ b/libs/video/renderer/vulkan/vkgen/vkenum.h @@ -11,6 +11,7 @@ } -(void) writeTable; -(void) writeSymtabInit; +-(void) writeSymtabEntry; @end #endif//__renderer_vulkan_vkgen_vkenum_h diff --git a/libs/video/renderer/vulkan/vkgen/vkenum.r b/libs/video/renderer/vulkan/vkgen/vkenum.r index 9f12c013e..22342cb1c 100644 --- a/libs/video/renderer/vulkan/vkgen/vkenum.r +++ b/libs/video/renderer/vulkan/vkgen/vkenum.r @@ -147,6 +147,12 @@ skip_value(string name) [self name]); } +-(void) writeSymtabEntry +{ + fprintf (output_file, "\tHash_Add (enum_symtab, &%s_enum);\n", + [self name]); +} + -(string) cexprType { return [self name] + "_type"; diff --git a/libs/video/renderer/vulkan/vkgen/vkgen.r b/libs/video/renderer/vulkan/vkgen/vkgen.r index 7a1edab8a..d47873ad2 100644 --- a/libs/video/renderer/vulkan/vkgen/vkgen.r +++ b/libs/video/renderer/vulkan/vkgen/vkgen.r @@ -251,6 +251,7 @@ main(int argc, string *argv) } arp_start (); [obj writeSymtabInit]; + [obj writeSymtabEntry]; arp_end (); } fprintf (output_file, "}\n"); diff --git a/libs/video/renderer/vulkan/vkgen/vkstruct.h b/libs/video/renderer/vulkan/vkgen/vkstruct.h index 048b3332f..08b489592 100644 --- a/libs/video/renderer/vulkan/vkgen/vkstruct.h +++ b/libs/video/renderer/vulkan/vkgen/vkstruct.h @@ -16,6 +16,7 @@ -(qfot_var_t *)findField:(string) fieldName; -(void) writeTable; -(void) writeSymtabInit; +-(void) writeSymtabEntry; -(string) outname; @end diff --git a/libs/video/renderer/vulkan/vkgen/vkstruct.r b/libs/video/renderer/vulkan/vkgen/vkstruct.r index ac03d8f41..6d5c2cfc2 100644 --- a/libs/video/renderer/vulkan/vkgen/vkstruct.r +++ b/libs/video/renderer/vulkan/vkgen/vkstruct.r @@ -165,6 +165,10 @@ [self outname]); } +-(void) writeSymtabEntry +{ +} + -(string) outname { if (outname) { diff --git a/libs/video/renderer/vulkan/vkparse.c b/libs/video/renderer/vulkan/vkparse.c index d2ae12949..21e7bdf72 100644 --- a/libs/video/renderer/vulkan/vkparse.c +++ b/libs/video/renderer/vulkan/vkparse.c @@ -42,6 +42,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" @@ -50,6 +51,7 @@ #include "QF/sys.h" #include "QF/va.h" #include "QF/vid.h" +#include "QF/simd/vec4f.h" #include "QF/Vulkan/qf_vid.h" #include "QF/Vulkan/device.h" #include "QF/Vulkan/command.h" @@ -65,7 +67,10 @@ #include "vid_vulkan.h" #include "util.h" + +#define vkparse_internal #include "vkparse.h" +#undef vkparse_internal static void flag_or (const exprval_t *val1, const exprval_t *val2, exprval_t *result, exprctx_t *ctx) @@ -145,19 +150,16 @@ parse_basic (const plfield_t *field, const plitem_t *item, ectx.symtab = 0; ectx.result = &result; const char *valstr = PL_String (item); - //Sys_Printf ("parse_uint32_t: %s %zd %d %p %p: %s\n", + //Sys_Printf ("parse_basic: %s %zd %d %p %p: %s\n", // field->name, field->offset, field->type, field->parser, // field->data, valstr); if (strcmp (valstr, "VK_SUBPASS_EXTERNAL") == 0) { //FIXME handle subpass in a separate parser? *(uint32_t *) data = VK_SUBPASS_EXTERNAL; } else { - Sys_Printf ("parse_uint32_t: %s %zd %d %p %p %s\n", - field->name, field->offset, field->type, field->parser, - field->data, valstr); ret = !cexpr_eval_string (valstr, &ectx); - Sys_Printf (" %x\n", *(uint32_t *)data); } + //Sys_Printf (" %x\n", *(uint32_t *)data); return ret; } @@ -179,11 +181,11 @@ parse_uint32_t (const plfield_t *field, const plitem_t *item, //FIXME handle subpass in a separate parser? *(uint32_t *) data = VK_SUBPASS_EXTERNAL; } else { - Sys_Printf ("parse_uint32_t: %s %zd %d %p %p %s\n", - field->name, field->offset, field->type, field->parser, - field->data, valstr); + //Sys_Printf ("parse_uint32_t: %s %zd %d %p %p %s\n", + // field->name, field->offset, field->type, field->parser, + // field->data, valstr); ret = !cexpr_eval_string (valstr, &ectx); - Sys_Printf (" %d\n", *(uint32_t *)data); + //Sys_Printf (" %d\n", *(uint32_t *)data); } return ret; @@ -327,6 +329,23 @@ parse_custom (const plfield_t *field, const plitem_t *item, return custom->parse (item, offsets, messages, context); } + +static int +parse_VkShaderModule (const plitem_t *item, void **data, + plitem_t *messages, parsectx_t *context) +{ + vulkan_ctx_t *ctx = context->vctx; + const char *name = PL_String (item); + __auto_type mptr = (VkShaderModule *)data[0]; + VkShaderModule module = QFV_FindShaderModule (ctx, name); + if (module) { + *mptr = module; + return 1; + } + return 0; +} +static hashtab_t *enum_symtab; + #include "libs/video/renderer/vulkan/vkparse.cinc" typedef struct qfv_renderpass_s { @@ -421,9 +440,24 @@ QFV_ParseRenderPass (vulkan_ctx_t *ctx, plitem_t *plist) return renderpass; } +static const char * +enum_symtab_getkey (const void *e, void *unused) +{ + __auto_type enm = (const exprenum_t *) e; + return enm->type->name; +} + void QFV_InitParse (void) { exprctx_t context = {}; + enum_symtab = Hash_NewTable (61, enum_symtab_getkey, 0, 0, + &context.hashlinks); vkgen_init_symtabs (&context); } + +exprenum_t * +QFV_GetEnum (const char *name) +{ + return Hash_Find (enum_symtab, name); +} diff --git a/libs/video/renderer/vulkan/vkparse.h b/libs/video/renderer/vulkan/vkparse.h index b95475bda..e34624dab 100644 --- a/libs/video/renderer/vulkan/vkparse.h +++ b/libs/video/renderer/vulkan/vkparse.h @@ -3,7 +3,9 @@ #include "QF/cexpr.h" #include "QF/Vulkan/renderpass.h" +#ifdef vkparse_internal #include "libs/video/renderer/vulkan/vkparse.hinc" +#endif typedef struct parsectx_s { struct exprctx_s *ectx; @@ -12,5 +14,6 @@ typedef struct parsectx_s { VkRenderPass QFV_ParseRenderPass (vulkan_ctx_t *ctx, plitem_t *plist); void QFV_InitParse (void); +exprenum_t *QFV_GetEnum (const char *name); #endif//__vkparse_h diff --git a/libs/video/renderer/vulkan/vulkan_vid_common.c b/libs/video/renderer/vulkan/vulkan_vid_common.c index 78c4e9add..7647db9ff 100644 --- a/libs/video/renderer/vulkan/vulkan_vid_common.c +++ b/libs/video/renderer/vulkan/vulkan_vid_common.c @@ -98,11 +98,12 @@ msaaSamples_f (cvar_t *var) exprctx_t context = {}; context.memsuper = new_memsuper(); - if (cexpr_parse_enum (&VkSampleCountFlagBits_enum, var->string, &context, - &var->int_val)) { + if (cexpr_parse_enum (QFV_GetEnum ("VkSampleCountFlagBits"), var->string, + &context, &var->int_val)) { Sys_Printf ("Invalid MSAA samples, using 1\n"); var->int_val = VK_SAMPLE_COUNT_1_BIT; } + delete_memsuper (context.memsuper); } static void