From 2430f44d7b0330d49db79c32726f8dbbe76d9cb3 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 24 Dec 2020 09:58:27 +0900 Subject: [PATCH] [vulkan] Support parsing numeric types --- libs/video/renderer/vulkan/vkgen/vktype.r | 12 +++++ libs/video/renderer/vulkan/vkparse.c | 54 +++++++++++++++++------ 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/libs/video/renderer/vulkan/vkgen/vktype.r b/libs/video/renderer/vulkan/vkgen/vktype.r index 5d6c1b7ae..fbe44e350 100644 --- a/libs/video/renderer/vulkan/vkgen/vktype.r +++ b/libs/video/renderer/vulkan/vkgen/vktype.r @@ -74,6 +74,9 @@ static string get_type_key (void *type, void *unused) -(string) name { + if (type.meta == ty_basic) { + return pr_type_name[type.type]; + } //FIXME extract alias name and return proper type name return type.encoding; } @@ -98,16 +101,25 @@ static string get_type_key (void *type, void *unused) -(string) parseType { + if (type.meta == ty_basic) { + return "QFString"; + } return "no parse"; } -(string) parseFunc { + if (type.meta == ty_basic) { + return "parse_basic"; + } return "0"; } -(string) parseData { + if (type.meta == ty_basic) { + return "&cexpr_" + pr_type_name[type.type]; + } return "0"; } diff --git a/libs/video/renderer/vulkan/vkparse.c b/libs/video/renderer/vulkan/vkparse.c index 5b198a807..ac198e756 100644 --- a/libs/video/renderer/vulkan/vkparse.c +++ b/libs/video/renderer/vulkan/vkparse.c @@ -135,29 +135,55 @@ typedef struct parse_custom_s { } parse_custom_t; static int -parse_uint32_t (const plfield_t *field, const plitem_t *item, - void *data, plitem_t *messages, void *context) +parse_basic (const plfield_t *field, const plitem_t *item, + void *data, plitem_t *messages, void *context) { int ret = 1; + __auto_type etype = (exprtype_t *) field->data; + exprctx_t ectx = *((parsectx_t *) context)->ectx; + exprval_t result = { etype, data }; + ectx.symtab = 0; + ectx.result = &result; const char *valstr = PL_String (item); //Sys_Printf ("parse_uint32_t: %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 { - char *end; - unsigned long val = strtoul (valstr, &end, 0); - if (*valstr && !*end && val <= 0xffffffff) { - *(uint32_t *) data = val; - } else if (val > 0xffffffff) { - PL_Message (messages, item, "%lu bigger than 32 bits", val); - ret = 0; - } else { - PL_Message (messages, item, "invalid char at %d in '%s'\n", - (int) (end - valstr), valstr); - ret = 0; - } + 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); + } + + return ret; +} + +static int +parse_uint32_t (const plfield_t *field, const plitem_t *item, + void *data, plitem_t *messages, void *context) +{ + int ret = 1; + exprctx_t ectx = *((parsectx_t *) context)->ectx; + exprval_t result = { &cexpr_uint, data }; + ectx.symtab = 0; + ectx.result = &result; + const char *valstr = PL_String (item); + //Sys_Printf ("parse_uint32_t: %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 (" %d\n", *(uint32_t *)data); } return ret;