[qfcc] Create defs for instanced interface blocks

And allow unsized arrays (for in, uniform and buffer) to have deferred
sizes.
This commit is contained in:
Bill Currie 2024-09-01 17:10:10 +09:00
parent f0eccc398e
commit 0385345d63
2 changed files with 30 additions and 4 deletions

View file

@ -106,6 +106,15 @@ set_storage_bits (def_t *def, storage_class_t storage)
}
}
static bool
deferred_size (storage_class_t storage)
{
if (storage == sc_in || storage == sc_uniform || storage == sc_buffer) {
return true;
}
return false;
}
def_t *
new_def (const char *name, const type_t *type, defspace_t *space,
storage_class_t storage)
@ -151,7 +160,7 @@ new_def (const char *name, const type_t *type, defspace_t *space,
int size = type_size (type);
int alignment = type->alignment;
if (!size) {
if (!size && is_array (type) && !deferred_size (storage)) {
error (0, "%s has incomplete type", name);
size = 1;
alignment = 1;
@ -160,7 +169,9 @@ new_def (const char *name, const type_t *type, defspace_t *space,
print_type (type);
internal_error (0, "type has no alignment");
}
def->offset = defspace_alloc_aligned_loc (space, size, alignment);
if (size) {
def->offset = defspace_alloc_aligned_loc (space, size, alignment);
}
}
return def;

View file

@ -38,6 +38,7 @@
#include "tools/qfcc/include/shared.h"
#include "tools/qfcc/include/strpool.h"
#include "tools/qfcc/include/symtab.h"
#include "tools/qfcc/include/type.h"
ALLOC_STATE (glsl_block_t, blocks);
@ -109,7 +110,7 @@ glsl_declare_block (specifier_t spec, symbol_t *block_sym,
break;
}
if (!block_tab) {
error (0, "invalid storage for block");
error (0, "invalid storage for block: %d", spec.storage);
return;
}
glsl_block_t *block;
@ -127,7 +128,21 @@ glsl_declare_block (specifier_t spec, symbol_t *block_sym,
sym->def = def;
}
if (instance_name) {
//namespace_add (instance_name, block->members);
auto type = new_type ();
*type = (type_t) {
.type = ev_invalid,
.name = save_string (block_sym->name),
.alignment = 4,
.width = 1,
.columns = 1,
.meta = ty_struct,
.symtab = block->members,
};
instance_name->type = append_type (instance_name->type, type);
instance_name->type = find_type (instance_name->type);
auto space = current_symtab->space;// FIXME
initialize_def (instance_name, nullptr, space, spec.storage,
current_symtab);
} else {
for (auto sym = block->members->symbols; sym; sym = sym->next) {
auto new = new_symbol (sym->name);