[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.
This commit is contained in:
Bill Currie 2021-01-04 17:26:39 +09:00
parent a6a3d4c6b5
commit e4f75791ce
11 changed files with 62 additions and 31 deletions

View file

@ -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

View file

@ -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"

View file

@ -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;
}

View file

@ -11,6 +11,7 @@
}
-(void) writeTable;
-(void) writeSymtabInit;
-(void) writeSymtabEntry;
@end
#endif//__renderer_vulkan_vkgen_vkenum_h

View file

@ -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";

View file

@ -251,6 +251,7 @@ main(int argc, string *argv)
}
arp_start ();
[obj writeSymtabInit];
[obj writeSymtabEntry];
arp_end ();
}
fprintf (output_file, "}\n");

View file

@ -16,6 +16,7 @@
-(qfot_var_t *)findField:(string) fieldName;
-(void) writeTable;
-(void) writeSymtabInit;
-(void) writeSymtabEntry;
-(string) outname;
@end

View file

@ -165,6 +165,10 @@
[self outname]);
}
-(void) writeSymtabEntry
{
}
-(string) outname
{
if (outname) {

View file

@ -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);
}

View file

@ -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

View file

@ -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