mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 12:52:46 +00:00
[vulkan] Split up vkgen
It worked as a proof of concept, but as the code itself needs to be a bit smarter, it would be a lot smarter to break up that code to make it easier to work on the individual parts.
This commit is contained in:
parent
8bd5f4f201
commit
2ca9f80d56
9 changed files with 228 additions and 159 deletions
|
@ -2,7 +2,10 @@ vkgen = libs/video/renderer/vulkan/vkgen.dat$(EXEEXT)
|
|||
noinst_PROGRAMS += $(vkgen)
|
||||
|
||||
vkgen_dat_src= \
|
||||
libs/video/renderer/vulkan/vkgen/vkenum.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkgen.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkstruct.r \
|
||||
libs/video/renderer/vulkan/vkgen/vktype.r \
|
||||
libs/video/renderer/vulkan/vkgen/vulkan.r
|
||||
|
||||
VKGENFLAGS = -I$(top_srcdir)/libs/video/renderer/vulkan/vkgen
|
||||
|
@ -29,6 +32,10 @@ libs/video/renderer/vulkan/vkgen/vulkan.o: $(top_srcdir)/libs/video/renderer/vul
|
|||
|
||||
EXTRA_DIST += \
|
||||
libs/video/renderer/vulkan/vkgen/stddef.h \
|
||||
libs/video/renderer/vulkan/vkgen/stdint.h
|
||||
libs/video/renderer/vulkan/vkgen/stdint.h \
|
||||
libs/video/renderer/vulkan/vkgen/vkenum.h \
|
||||
libs/video/renderer/vulkan/vkgen/vkgen.h \
|
||||
libs/video/renderer/vulkan/vkgen/vkstruct.h \
|
||||
libs/video/renderer/vulkan/vkgen/vktype.h \
|
||||
CLEANFILES += \
|
||||
libs/video/renderer/vkgen/*.sym
|
||||
|
|
13
libs/video/renderer/vulkan/vkgen/vkenum.h
Normal file
13
libs/video/renderer/vulkan/vkgen/vkenum.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef __renderer_vulkan_vkgen_vkenum_h
|
||||
#define __renderer_vulkan_vkgen_vkenum_h
|
||||
|
||||
#include "vktype.h"
|
||||
|
||||
@interface Enum: Type
|
||||
{
|
||||
int prefix_length;
|
||||
}
|
||||
-(void) writeTable;
|
||||
@end
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vkenum_h
|
75
libs/video/renderer/vulkan/vkgen/vkenum.r
Normal file
75
libs/video/renderer/vulkan/vkgen/vkenum.r
Normal file
|
@ -0,0 +1,75 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "vkenum.h"
|
||||
#include "vkgen.h"
|
||||
|
||||
@implementation Enum
|
||||
-(void)process
|
||||
{
|
||||
string end = "_MAX_ENUM";
|
||||
int len;
|
||||
string prefix = nil;
|
||||
|
||||
if (str_mid([self name], -8) == "FlagBits") {
|
||||
end = "_FLAG_BITS_MAX_ENUM";
|
||||
}
|
||||
len = -strlen (end);
|
||||
for (int i = 0; i < type.strct.num_fields; i++) {
|
||||
qfot_var_t *var = &type.strct.fields[i];
|
||||
if (str_mid (var.name, len) == end) {
|
||||
// len is negative so +1 consumes 1 more char (_)
|
||||
prefix = str_hold (str_mid (var.name, 0, len + 1));
|
||||
}
|
||||
}
|
||||
if (prefix) {
|
||||
prefix_length = strlen (prefix);
|
||||
}
|
||||
}
|
||||
|
||||
-initWithType: (qfot_type_t *) type
|
||||
{
|
||||
if (!(self = [super initWithType: type])) {
|
||||
return nil;
|
||||
}
|
||||
[self process];
|
||||
return self;
|
||||
}
|
||||
|
||||
-(string) name
|
||||
{
|
||||
return str_mid(type.strct.tag, 4);
|
||||
}
|
||||
|
||||
-(void) writeTable
|
||||
{
|
||||
int strip_bit = 0;
|
||||
if (str_mid([self name], -8) == "FlagBits") {
|
||||
strip_bit = 1;
|
||||
}
|
||||
|
||||
fprintf (output_file, "enumval_t %s_values[] = {\n", [self name]);
|
||||
for (int i = 0; i < type.strct.num_fields; i++) {
|
||||
qfot_var_t *var = &type.strct.fields[i];
|
||||
if (str_str (var.name, "_MAX_ENUM") >= 0
|
||||
|| str_str (var.name, "_BEGIN_RANGE") >= 0
|
||||
|| str_str (var.name, "_END_RANGE") >= 0
|
||||
|| str_str (var.name, "_RANGE_SIZE") >= 0) {
|
||||
continue;
|
||||
}
|
||||
fprintf (output_file, "\t{\"%s\", %d},\n", var.name, var.offset);
|
||||
if (prefix_length) {
|
||||
string shortname = str_mid (var.name, prefix_length);
|
||||
if (strip_bit) {
|
||||
int bit_pos = str_str (shortname, "_BIT");
|
||||
if (bit_pos >= 0) {
|
||||
shortname = str_mid (shortname, 0, bit_pos);
|
||||
}
|
||||
}
|
||||
fprintf (output_file, "\t{\"%s\", %d},\n", str_lower(shortname),
|
||||
var.offset);
|
||||
}
|
||||
}
|
||||
fprintf (output_file, "\t{ }\n");
|
||||
fprintf (output_file, "};\n");
|
||||
}
|
||||
@end
|
18
libs/video/renderer/vulkan/vkgen/vkgen.h
Normal file
18
libs/video/renderer/vulkan/vkgen/vkgen.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef __renderer_vulkan_vkgen_vkgen_h
|
||||
#define __renderer_vulkan_vkgen_vkgen_h
|
||||
|
||||
#include <hash.h>
|
||||
#include <qfile.h>
|
||||
#include <types.h>
|
||||
#include <Array.h>
|
||||
|
||||
typedef void varfunc (qfot_var_t *var);
|
||||
|
||||
void printf (string fmt, ...);
|
||||
void fprintf (QFile file, string format, ...);
|
||||
extern Array *queue;
|
||||
extern Array *output_types;
|
||||
extern QFile output_file;
|
||||
extern hashtab_t *processed_types;
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vkgen_h
|
|
@ -5,6 +5,10 @@
|
|||
#include <types.h>
|
||||
#include <Array.h>
|
||||
|
||||
#include "vkgen.h"
|
||||
#include "vkstruct.h"
|
||||
#include "vkenum.h"
|
||||
|
||||
void printf (string fmt, ...) = #0;
|
||||
|
||||
void fprintf (QFile file, string format, ...)
|
||||
|
@ -13,8 +17,6 @@ void fprintf (QFile file, string format, ...)
|
|||
Qputs (file, vsprintf (format, va_copy (@args)));
|
||||
}
|
||||
|
||||
typedef void varfunc (qfot_var_t *var);
|
||||
|
||||
string search_names[] = {
|
||||
"VkGraphicsPipelineCreateInfo",
|
||||
"VkComputePipelineCreateInfo",
|
||||
|
@ -27,162 +29,6 @@ Array *output_types;
|
|||
|
||||
QFile output_file;
|
||||
|
||||
@interface Enum: Object
|
||||
{
|
||||
qfot_type_t *type;
|
||||
int prefix_length;
|
||||
}
|
||||
-initWithType: (qfot_type_t *) type;
|
||||
/** \warning returned string is ephemeral
|
||||
*/
|
||||
-(string) name;
|
||||
@end
|
||||
|
||||
@implementation Enum
|
||||
-(void)process
|
||||
{
|
||||
string end = "_MAX_ENUM";
|
||||
int len;
|
||||
string prefix = nil;
|
||||
|
||||
if (str_mid([self name], -8) == "FlagBits") {
|
||||
end = "_FLAG_BITS_MAX_ENUM";
|
||||
}
|
||||
len = -strlen (end);
|
||||
for (int i = 0; i < type.strct.num_fields; i++) {
|
||||
qfot_var_t *var = &type.strct.fields[i];
|
||||
if (str_mid (var.name, len) == end) {
|
||||
// len is negative so +1 consumes 1 more char (_)
|
||||
prefix = str_hold (str_mid (var.name, 0, len + 1));
|
||||
}
|
||||
}
|
||||
if (prefix) {
|
||||
prefix_length = strlen (prefix);
|
||||
}
|
||||
}
|
||||
|
||||
-initWithType: (qfot_type_t *) type
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
self.type = type;
|
||||
[self process];
|
||||
return self;
|
||||
}
|
||||
|
||||
-(string) name
|
||||
{
|
||||
return str_mid(type.strct.tag, 4);
|
||||
}
|
||||
|
||||
-(void) addToQueue
|
||||
{
|
||||
string name = [self name];
|
||||
//printf (" +%s\n", name);
|
||||
if (!Hash_Find (processed_types, name)) {
|
||||
Hash_Add (processed_types, (void *) name);
|
||||
[queue addObject: self];
|
||||
}
|
||||
}
|
||||
|
||||
-(void) writeTable
|
||||
{
|
||||
int strip_bit = 0;
|
||||
if (str_mid([self name], -8) == "FlagBits") {
|
||||
strip_bit = 1;
|
||||
}
|
||||
|
||||
fprintf (output_file, "enumval_t %s_values[] = {\n", [self name]);
|
||||
for (int i = 0; i < type.strct.num_fields; i++) {
|
||||
qfot_var_t *var = &type.strct.fields[i];
|
||||
if (str_str (var.name, "_MAX_ENUM") >= 0
|
||||
|| str_str (var.name, "_BEGIN_RANGE") >= 0
|
||||
|| str_str (var.name, "_END_RANGE") >= 0
|
||||
|| str_str (var.name, "_RANGE_SIZE") >= 0) {
|
||||
continue;
|
||||
}
|
||||
fprintf (output_file, "\t{\"%s\", %d},\n", var.name, var.offset);
|
||||
if (prefix_length) {
|
||||
string shortname = str_mid (var.name, prefix_length);
|
||||
if (strip_bit) {
|
||||
int bit_pos = str_str (shortname, "_BIT");
|
||||
if (bit_pos >= 0) {
|
||||
shortname = str_mid (shortname, 0, bit_pos);
|
||||
}
|
||||
}
|
||||
fprintf (output_file, "\t{\"%s\", %d},\n", str_lower(shortname),
|
||||
var.offset);
|
||||
}
|
||||
}
|
||||
fprintf (output_file, "\t{ }\n");
|
||||
fprintf (output_file, "};\n");
|
||||
}
|
||||
@end
|
||||
|
||||
@interface Struct: Object
|
||||
{
|
||||
qfot_type_t *type;
|
||||
}
|
||||
-initWithType: (qfot_type_t *) type;
|
||||
/** \warning returned string is ephemeral
|
||||
*/
|
||||
-(string) name;
|
||||
-(void) forEachFieldCall: (varfunc) func;
|
||||
@end
|
||||
|
||||
@implementation Struct
|
||||
-initWithType: (qfot_type_t *) type
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
self.type = type;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(string) name
|
||||
{
|
||||
return str_mid(type.strct.tag, 4);
|
||||
}
|
||||
|
||||
-(void) forEachFieldCall: (varfunc) func
|
||||
{
|
||||
qfot_struct_t *strct =&type.strct;
|
||||
|
||||
for (int i = 0; i < strct.num_fields; i++) {
|
||||
func (&strct.fields[i]);
|
||||
}
|
||||
}
|
||||
|
||||
-(void) addToQueue
|
||||
{
|
||||
string name = [self name];
|
||||
//printf (" +%s\n", name);
|
||||
if (!Hash_Find (processed_types, name)) {
|
||||
Hash_Add (processed_types, (void *) name);
|
||||
[queue addObject: self];
|
||||
}
|
||||
}
|
||||
|
||||
-(void) writeTable
|
||||
{
|
||||
fprintf (output_file, "structfld_t %s_fields[] = {\n", [self name]);
|
||||
for (int i = 0; i < type.strct.num_fields; i++) {
|
||||
qfot_var_t *var = &type.strct.fields[i];
|
||||
if (var.name == "sType" || var.name == "pNext") {
|
||||
continue;
|
||||
}
|
||||
string type_name = var.type.encoding;
|
||||
fprintf (output_file,
|
||||
"\t{\"%s\", field_offset (%s, %s), %s, %s}, // %s\n",
|
||||
var.name, [self name], var.name, "0", "0", type_name);
|
||||
}
|
||||
fprintf (output_file, "\t{ }\n");
|
||||
fprintf (output_file, "};\n");
|
||||
}
|
||||
@end
|
||||
|
||||
qfot_type_encodings_t *encodings;
|
||||
|
||||
qfot_type_t *
|
||||
|
|
16
libs/video/renderer/vulkan/vkgen/vkstruct.h
Normal file
16
libs/video/renderer/vulkan/vkgen/vkstruct.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef __renderer_vulkan_vkgen_vkstruct_h
|
||||
#define __renderer_vulkan_vkgen_vkstruct_h
|
||||
|
||||
#include <Object.h>
|
||||
|
||||
#include "vkgen.h"
|
||||
#include "vktype.h"
|
||||
|
||||
@interface Struct: Type
|
||||
{
|
||||
}
|
||||
-(void) forEachFieldCall: (varfunc) func;
|
||||
-(void) writeTable;
|
||||
@end
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vkstruct_h
|
43
libs/video/renderer/vulkan/vkgen/vkstruct.r
Normal file
43
libs/video/renderer/vulkan/vkgen/vkstruct.r
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include <hash.h>
|
||||
#include <qfile.h>
|
||||
#include <runtime.h>
|
||||
#include <string.h>
|
||||
#include <types.h>
|
||||
#include <Array.h>
|
||||
|
||||
#include "vkgen.h"
|
||||
#include "vkstruct.h"
|
||||
|
||||
@implementation Struct
|
||||
|
||||
-(string) name
|
||||
{
|
||||
return str_mid(type.strct.tag, 4);
|
||||
}
|
||||
|
||||
-(void) forEachFieldCall: (varfunc) func
|
||||
{
|
||||
qfot_struct_t *strct =&type.strct;
|
||||
|
||||
for (int i = 0; i < strct.num_fields; i++) {
|
||||
func (&strct.fields[i]);
|
||||
}
|
||||
}
|
||||
|
||||
-(void) writeTable
|
||||
{
|
||||
fprintf (output_file, "structfld_t %s_fields[] = {\n", [self name]);
|
||||
for (int i = 0; i < type.strct.num_fields; i++) {
|
||||
qfot_var_t *var = &type.strct.fields[i];
|
||||
if (var.name == "sType" || var.name == "pNext") {
|
||||
continue;
|
||||
}
|
||||
string type_name = var.type.encoding;
|
||||
fprintf (output_file,
|
||||
"\t{\"%s\", field_offset (%s, %s), %s, %s}, // %s\n",
|
||||
var.name, [self name], var.name, "0", "0", type_name);
|
||||
}
|
||||
fprintf (output_file, "\t{ }\n");
|
||||
fprintf (output_file, "};\n");
|
||||
}
|
||||
@end
|
18
libs/video/renderer/vulkan/vkgen/vktype.h
Normal file
18
libs/video/renderer/vulkan/vkgen/vktype.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef __renderer_vulkan_vkgen_vktype_h
|
||||
#define __renderer_vulkan_vkgen_vktype_h
|
||||
|
||||
#include <types.h>
|
||||
#include <Object.h>
|
||||
|
||||
@interface Type: Object
|
||||
{
|
||||
qfot_type_t *type;
|
||||
}
|
||||
-initWithType: (qfot_type_t *) type;
|
||||
/** \warning returned string is ephemeral
|
||||
*/
|
||||
-(string) name;
|
||||
-(void) addToQueue;
|
||||
@end
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vktype_h
|
33
libs/video/renderer/vulkan/vkgen/vktype.r
Normal file
33
libs/video/renderer/vulkan/vkgen/vktype.r
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include <hash.h>
|
||||
|
||||
#include "vkgen.h"
|
||||
#include "vktype.h"
|
||||
|
||||
@implementation Type
|
||||
|
||||
-initWithType: (qfot_type_t *) type
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
self.type = type;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(string) name
|
||||
{
|
||||
//FIXME extract alias name and return proper type name
|
||||
return type.encoding;
|
||||
}
|
||||
|
||||
-(void) addToQueue
|
||||
{
|
||||
string name = [self name];
|
||||
//printf (" +%s\n", name);
|
||||
if (!Hash_Find (processed_types, name)) {
|
||||
Hash_Add (processed_types, (void *) name);
|
||||
[queue addObject: self];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in a new issue