[vkgen] Add support for fixed arrays

I want to support reading VkPhysicalDeviceLimits but it has some arrays.
While I don't need to parse them (VkPhysicalDeviceLimits should be
treated as read-only), I do need to be able to access them in property
list expressions, and vkgen generates the cexpr type descriptors too.

However, I will probably want to parse arrays some time in the future.
This commit is contained in:
Bill Currie 2021-12-04 10:08:27 +09:00
parent c8846f8007
commit 8271860fb3
6 changed files with 166 additions and 3 deletions

View file

@ -14,6 +14,7 @@ vkgen_dat_src= \
libs/video/renderer/vulkan/vkgen/vkfieldsingle.r \
libs/video/renderer/vulkan/vkgen/vkfieldstring.r \
libs/video/renderer/vulkan/vkgen/vkfieldtype.r \
libs/video/renderer/vulkan/vkgen/vkfixedarray.r \
libs/video/renderer/vulkan/vkgen/vkgen.r \
libs/video/renderer/vulkan/vkgen/vkstruct.r \
libs/video/renderer/vulkan/vkgen/vktype.r \
@ -55,6 +56,7 @@ EXTRA_DIST += \
libs/video/renderer/vulkan/vkgen/vkfieldsingle.h \
libs/video/renderer/vulkan/vkgen/vkfieldstring.h \
libs/video/renderer/vulkan/vkgen/vkfieldtype.h \
libs/video/renderer/vulkan/vkgen/vkfixedarray.h \
libs/video/renderer/vulkan/vkgen/vkgen.h \
libs/video/renderer/vulkan/vkgen/vkstruct.h \
libs/video/renderer/vulkan/vkgen/vktype.h

View file

@ -0,0 +1,19 @@
#ifndef __renderer_vulkan_vkgen_vkfixedarray_h
#define __renderer_vulkan_vkgen_vkfixedarray_h
#include <Object.h>
#include "vkgen.h"
#include "vktype.h"
@interface FixedArray: Type
{
Type *ele_type;
int ele_count;
}
-(void) writeTable;
-(void) writeSymtabInit;
-(void) writeSymtabEntry;
@end
#endif//__renderer_vulkan_vkgen_vkfixedarray_h

View file

@ -0,0 +1,92 @@
#include <hash.h>
#include <qfile.h>
#include <runtime.h>
#include <string.h>
#include <types.h>
#include <Array.h>
#include <PropertyList.h>
#include "vkfielddef.h"
#include "vkgen.h"
#include "vkfixedarray.h"
@implementation FixedArray
-initWithType: (qfot_type_t *) type
{
if (!(self = [super initWithType: type])) {
return nil;
}
ele_type = [Type fromType: type.array.type];
ele_count = type.array.size;
return self;
}
-(string) name
{
return sprintf ("%s_array_%d", [ele_type name], ele_count);
}
-(void) addToQueue
{
string name = [self name];
if (!Hash_Find (processed_types, name)) {
//printf (" +%s\n", name);
Hash_Add (processed_types, (void *) name);
[queue addObject: self];
}
}
-(void) writeTable
{
fprintf (output_file, "static parse_fixed_array_t parse_%s_data = {\n",
[self name]);
fprintf (output_file, "\t%s,\n", [ele_type parseType]);
fprintf (output_file, "\tsizeof (%s),\n", [ele_type name]);
fprintf (output_file, "\t%s,\n", [ele_type parseFunc]);
fprintf (output_file, "\t%d,\n", ele_count);
fprintf (output_file, "};\n");
fprintf (output_file, "exprarray_t %s_array = {\n", [self name]);
fprintf (output_file, "\t&%s,\n", [ele_type cexprType]);
fprintf (output_file, "\t%d,\n", ele_count);
fprintf (output_file, "};\n");
fprintf (output_file, "exprtype_t %s_type = {\n", [self name]);
fprintf (output_file, "\t\"%s[%d]\",\n", [ele_type name], ele_count);
fprintf (output_file, "\t%d * sizeof (%s),\n", ele_count, [ele_type name]);
fprintf (output_file, "\tcexpr_array_binops,\n");
fprintf (output_file, "\t0,\n");
fprintf (output_file, "\t&%s_array,\n", [self name]);
fprintf (output_file, "};\n");
fprintf (output_file, "\n");
fprintf (header_file, "extern exprtype_t %s_type;\n", [self name]);
}
-(void) writeSymtabInit
{
}
-(void) writeSymtabEntry
{
}
-(string) cexprType
{
return [self name] + "_type";
}
-(string) parseType
{
return "QFMultiType | (1 << QFString) | (1 << QFArray)";
}
-(string) parseFunc
{
return "parse_fixed_array";
}
-(string) parseData
{
return "&parse_" + [self name] + "_data";;
}
@end

View file

@ -9,6 +9,7 @@
#include "vkgen.h"
#include "vkstruct.h"
#include "vkfixedarray.h"
#include "vkenum.h"
static AutoreleasePool *autorelease_pool;
@ -228,6 +229,19 @@ main(int argc, string *argv)
[obj writeTable];
arp_end ();
}
for (int i = [output_types count]; i-- > 0; ) {
id obj = [output_types objectAtIndex:i];
if ([obj name] == "VkStructureType") {
continue;
}
if ([obj class] != [FixedArray class]) {
continue;
}
arp_start ();
[obj writeTable];
arp_end ();
}
for (int i = [output_types count]; i-- > 0; ) {
id obj = [output_types objectAtIndex:i];
if ([obj name] == "VkStructureType") {

View file

@ -2,6 +2,7 @@
#include "vkalias.h"
#include "vkenum.h"
#include "vkfixedarray.h"
#include "vkgen.h"
#include "vkstruct.h"
#include "vktype.h"
@ -50,9 +51,10 @@ static string get_type_key (void *type, void *unused)
}
switch (type.meta) {
case ty_basic:
case ty_array:
case ty_class:
return [[Type alloc] initWithType: type];
case ty_array:
return [[FixedArray alloc] initWithType: type];
case ty_enum:
return [[Enum alloc] initWithType: type];
case ty_struct:
@ -62,7 +64,7 @@ static string get_type_key (void *type, void *unused)
if (type.alias.name) {
return [[Alias alloc] initWithType: type];
}
break;
return [Type fromType: type.alias.full_type];
}
return nil;
}
@ -107,7 +109,7 @@ static string get_type_key (void *type, void *unused)
if (type.meta == ty_basic) {
return "QFString";
}
return "no parse";
return "no parse " + [self name];
}
-(string) parseFunc

View file

@ -131,6 +131,13 @@ typedef struct parse_array_s {
size_t size_offset;
} parse_array_t;
typedef struct parse_fixed_array_s {
pltype_t type;
size_t stride;
plparser_t parser;
size_t size;
} parse_fixed_array_t;
typedef struct parse_data_s {
size_t value_offset;
size_t size_offset;
@ -323,6 +330,33 @@ parse_array (const plfield_t *field, const plitem_t *item,
return 1;
}
static int
parse_fixed_array (const plfield_t *field, const plitem_t *item,
void *data, plitem_t *messages, void *context)
{
__auto_type array = (parse_fixed_array_t *) field->data;
plelement_t element = {
array->type,
array->stride,
vkparse_alloc,
array->parser,
0,
};
plfield_t f = { 0, 0, 0, 0, &element };
typedef struct arr_s DARRAY_TYPE(byte) arr_t;
arr_t *arr;
if (!PL_ParseArray (&f, item, &arr, messages, context)) {
return 0;
}
memset (data, 0, array->stride * array->size);
size_t size = min (array->size, arr->size);
memcpy (data, arr->a, array->stride * size);
return 1;
}
static int
parse_string (const plfield_t *field, const plitem_t *item,
void *data, plitem_t *messages, void *context)