mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-14 00:40:55 +00:00
[vulkan] Implement most of the parser
This gets renderpass parsing almost working (not hooked up, though). The missing bits are support for expressions for flags (namely support for the | operator) and references (eg $swapchain.format). However, this shows that the basic concept for the parser is working.
This commit is contained in:
parent
8184c546db
commit
f4c8d341e1
2 changed files with 126 additions and 9 deletions
|
@ -74,6 +74,8 @@
|
||||||
field_type = [[Type lookup: type_type] dereference];
|
field_type = [[Type lookup: type_type] dereference];
|
||||||
fprintf (output_file, "static parse_%s_t parse_%s_%s_data = {\n",
|
fprintf (output_file, "static parse_%s_t parse_%s_%s_data = {\n",
|
||||||
type_record, [self name], field_name);
|
type_record, [self name], field_name);
|
||||||
|
fprintf (output_file, "\t%s,\n", [field_type parseType]);
|
||||||
|
fprintf (output_file, "\tsizeof (%s),\n", type_type);
|
||||||
fprintf (output_file, "\tparse_%s,\n", type_type);
|
fprintf (output_file, "\tparse_%s,\n", type_type);
|
||||||
if (type_record == "single") {
|
if (type_record == "single") {
|
||||||
value_field = [[field_def getObjectForKey:"value"] string];
|
value_field = [[field_def getObjectForKey:"value"] string];
|
||||||
|
|
|
@ -70,45 +70,160 @@ typedef struct enumval_s {
|
||||||
} enumval_t;
|
} enumval_t;
|
||||||
|
|
||||||
typedef struct parse_single_s {
|
typedef struct parse_single_s {
|
||||||
|
pltype_t type;
|
||||||
|
size_t stride;
|
||||||
plparser_t parser;
|
plparser_t parser;
|
||||||
size_t value_offset;
|
size_t value_offset;
|
||||||
} parse_single_t;
|
} parse_single_t;
|
||||||
|
|
||||||
typedef struct parse_array_s {
|
typedef struct parse_array_s {
|
||||||
|
pltype_t type;
|
||||||
|
size_t stride;
|
||||||
plparser_t parser;
|
plparser_t parser;
|
||||||
size_t size_offset;
|
|
||||||
size_t value_offset;
|
size_t value_offset;
|
||||||
|
size_t size_offset;
|
||||||
} parse_array_t;
|
} parse_array_t;
|
||||||
|
|
||||||
|
static int find_enum (const char *valstr, enumval_t *enumval, int *val)
|
||||||
|
{
|
||||||
|
while (enumval->name && strcmp (enumval->name, valstr) != 0) {
|
||||||
|
enumval++;
|
||||||
|
}
|
||||||
|
if (enumval->name) {
|
||||||
|
*val = enumval->value;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int parse_uint32_t (const plfield_t *field, const plitem_t *item,
|
static int parse_uint32_t (const plfield_t *field, const plitem_t *item,
|
||||||
void *data, plitem_t *messages)
|
void *data, plitem_t *messages)
|
||||||
{
|
{
|
||||||
return 0;
|
int ret = 1;
|
||||||
|
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) {
|
||||||
|
*(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_enum (const plfield_t *field, const plitem_t *item,
|
static int parse_enum (const plfield_t *field, const plitem_t *item,
|
||||||
void *data, plitem_t *messages)
|
void *data, plitem_t *messages)
|
||||||
{
|
{
|
||||||
return 0;
|
int ret = 1;
|
||||||
|
int val;
|
||||||
|
const char *valstr = PL_String (item);
|
||||||
|
__auto_type enumval = (enumval_t *) field->data;
|
||||||
|
//Sys_Printf ("parse_enum: %s %zd %d %p %p %s\n",
|
||||||
|
// field->name, field->offset, field->type, field->parser,
|
||||||
|
// field->data, valstr);
|
||||||
|
if (find_enum (valstr, enumval, &val)) {
|
||||||
|
*(int *) data = val;
|
||||||
|
} else {
|
||||||
|
PL_Message (messages, item, "invalid enum: %s", valstr);
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_flags (const plfield_t *field, const plitem_t *item,
|
static int parse_flags (const plfield_t *field, const plitem_t *item,
|
||||||
void *data, plitem_t *messages)
|
void *data, plitem_t *messages)
|
||||||
{
|
{
|
||||||
return 0;
|
int ret = 1;
|
||||||
|
int val;
|
||||||
|
const char *valstr = PL_String (item);
|
||||||
|
__auto_type enumval = (enumval_t *) field->data;
|
||||||
|
//Sys_Printf ("parse_flags: %s %zd %d %p %p %s\n",
|
||||||
|
// field->name, field->offset, field->type, field->parser,
|
||||||
|
// field->data, valstr);
|
||||||
|
if (find_enum (valstr, enumval, &val)) {
|
||||||
|
*(int *) data = val;
|
||||||
|
} else if (strcmp (valstr, "0") == 0) {
|
||||||
|
*(int *) data = 0;
|
||||||
|
} else {
|
||||||
|
PL_Message (messages, item, "invalid enum: %s", valstr);
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_single (const plfield_t *field, const plitem_t *item,
|
static int parse_single (const plfield_t *field, const plitem_t *item,
|
||||||
void *data, plitem_t *messages)
|
void *data, plitem_t *messages)
|
||||||
{
|
{
|
||||||
|
__auto_type single = (parse_single_t *) field->data;
|
||||||
|
void *flddata = (byte *)data + single->value_offset;
|
||||||
|
|
||||||
|
//Sys_Printf ("parse_single: %s %zd %d %p %p\n", field->name, field->offset,
|
||||||
|
// field->type, field->parser, field->data);
|
||||||
|
|
||||||
|
if (PL_Type (item) != single->type) {
|
||||||
|
PL_Message (messages, item, "error: wrong type");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plfield_t f = { 0, 0, single->type, single->parser, 0 };
|
||||||
|
void *value = calloc (1, single->stride);
|
||||||
|
if (!single->parser (&f, item, value, messages)) {
|
||||||
|
free (value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(void **) flddata = value;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int parse_array (const plfield_t *field, const plitem_t *item,
|
static int parse_array (const plfield_t *field, const plitem_t *item,
|
||||||
void *data, plitem_t *messages)
|
void *data, plitem_t *messages)
|
||||||
{
|
{
|
||||||
|
__auto_type array = (parse_array_t *) field->data;
|
||||||
|
__auto_type value = (void **) ((byte *)data + array->value_offset);
|
||||||
|
__auto_type size = (uint32_t *) ((byte *)data + array->size_offset);
|
||||||
|
|
||||||
|
plelement_t element = {
|
||||||
|
array->type,
|
||||||
|
array->stride,
|
||||||
|
malloc,
|
||||||
|
array->parser,
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
plfield_t f = { 0, 0, 0, 0, &element };
|
||||||
|
|
||||||
|
typedef struct arr_s DARRAY_TYPE(byte) arr_t;
|
||||||
|
arr_t *arr;
|
||||||
|
|
||||||
|
//Sys_Printf ("parse_array: %s %zd %d %p %p %p\n",
|
||||||
|
// field->name, field->offset, field->type, field->parser,
|
||||||
|
// field->data, data);
|
||||||
|
//Sys_Printf (" %d %zd %p %zd %zd\n", array->type, array->stride,
|
||||||
|
// array->parser, array->value_offset, array->size_offset);
|
||||||
|
if (!PL_ParseArray (&f, item, &arr, messages)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*value = malloc (array->stride * arr->size);
|
||||||
|
memcpy (*value, arr->a, array->stride * arr->size);
|
||||||
|
if ((void *) size > data) {
|
||||||
|
*size = arr->size;
|
||||||
|
}
|
||||||
|
free (arr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
#include "libs/video/renderer/vulkan/vkparse.inc"
|
#include "libs/video/renderer/vulkan/vkparse.inc"
|
||||||
|
|
||||||
|
@ -144,11 +259,11 @@ static plelement_t parse_qfv_renderpass_dependencies_data = {
|
||||||
|
|
||||||
static plfield_t renderpass_fields[] = {
|
static plfield_t renderpass_fields[] = {
|
||||||
{ "attachments", field_offset (qfv_renderpass_t, attachments), QFArray,
|
{ "attachments", field_offset (qfv_renderpass_t, attachments), QFArray,
|
||||||
parse_array, &parse_qfv_renderpass_attachments_data },
|
PL_ParseArray, &parse_qfv_renderpass_attachments_data },
|
||||||
{ "subpasses", field_offset (qfv_renderpass_t, subpasses), QFArray,
|
{ "subpasses", field_offset (qfv_renderpass_t, subpasses), QFArray,
|
||||||
parse_array, &parse_qfv_renderpass_subpasses_data },
|
PL_ParseArray, &parse_qfv_renderpass_subpasses_data },
|
||||||
{ "dependencies", field_offset (qfv_renderpass_t, dependencies), QFArray,
|
{ "dependencies", field_offset (qfv_renderpass_t, dependencies), QFArray,
|
||||||
parse_array, &parse_qfv_renderpass_dependencies_data },
|
PL_ParseArray, &parse_qfv_renderpass_dependencies_data },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue