From 0385345d63b0b46a54b6559f0fe417007bec0843 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 1 Sep 2024 17:10:10 +0900 Subject: [PATCH] [qfcc] Create defs for instanced interface blocks And allow unsized arrays (for in, uniform and buffer) to have deferred sizes. --- tools/qfcc/source/def.c | 15 +++++++++++++-- tools/qfcc/source/glsl-block.c | 19 +++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/tools/qfcc/source/def.c b/tools/qfcc/source/def.c index 27fb6d9a2..03b877378 100644 --- a/tools/qfcc/source/def.c +++ b/tools/qfcc/source/def.c @@ -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; diff --git a/tools/qfcc/source/glsl-block.c b/tools/qfcc/source/glsl-block.c index 4aa1d270f..c173cf845 100644 --- a/tools/qfcc/source/glsl-block.c +++ b/tools/qfcc/source/glsl-block.c @@ -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);