From dc85a4df4be3ea696d34064104beab0cffe0f92d Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 14 Nov 2024 20:58:21 +0900 Subject: [PATCH] [qfcc] Specify entry-point interface variables Yet another step closer to having a working glsl compiler. --- tools/qfcc/include/spirv.h | 5 +++++ tools/qfcc/source/target_spirv.c | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/qfcc/include/spirv.h b/tools/qfcc/include/spirv.h index 064879b16..d94dd7a50 100644 --- a/tools/qfcc/include/spirv.h +++ b/tools/qfcc/include/spirv.h @@ -30,9 +30,13 @@ #include +#include "QF/darray.h" + #include "tools/qfcc/include/defspace.h" #include "tools/qfcc/include/expr.h" +typedef struct symbol_s symbol_t; + typedef struct entrypoint_s { struct entrypoint_s *next; SpvExecutionModel model; @@ -47,6 +51,7 @@ typedef struct module_s { ex_list_t extinst_imports; const expr_t *addressing_model; const expr_t *memory_model; + struct DARRAY_TYPE (symbol_t *) interface_syms; //entrypoint_t *entry_points; defspace_t *entry_points; defspace_t *exec_modes; diff --git a/tools/qfcc/source/target_spirv.c b/tools/qfcc/source/target_spirv.c index 7a0de08e0..0af757ee2 100644 --- a/tools/qfcc/source/target_spirv.c +++ b/tools/qfcc/source/target_spirv.c @@ -470,6 +470,8 @@ spirv_variable (symbol_t *sym, spirvctx_t *ctx) auto storage = spirv_storage_class (sym->var.storage); if (storage == SpvStorageClassFunction) { space = ctx->decl_space; + } else { + DARRAY_APPEND (&ctx->module->interface_syms, sym); } auto type = sym->type; unsigned tid = type_id (type, ctx); @@ -584,11 +586,16 @@ spirv_EntryPoint (unsigned func_id, const char *func_name, SpvExecutionModel model, spirvctx_t *ctx) { int len = strlen (func_name) + 1; + int iface_start = 3 + RUP(len, 4) / 4; auto linkage = ctx->module->entry_points; - auto insn = spirv_new_insn (SpvOpEntryPoint, 3 + RUP(len, 4) / 4, linkage); + int count = ctx->module->interface_syms.size; + auto insn = spirv_new_insn (SpvOpEntryPoint, iface_start + count, linkage); INSN (insn, 1) = model; INSN (insn, 2) = func_id; memcpy (&INSN (insn, 3), func_name, len); + for (int i = 0; i < count; i++) { + INSN (insn, iface_start + i) = ctx->module->interface_syms.a[i]->id; + } } typedef struct { @@ -1169,6 +1176,7 @@ spirv_write (struct pr_info_s *pr, const char *filename) pr->module->globals = defspace_new (ds_backed); pr->module->func_declarations = defspace_new (ds_backed); pr->module->func_definitions = defspace_new (ds_backed); + DARRAY_INIT (&pr->module->interface_syms, 16); spirvctx_t ctx = { .module = pr->module,