From 3dc22d8cd6e2a52581ac6f45ddc8d1c280589212 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 18 Nov 2024 15:47:22 +0900 Subject: [PATCH] [qfcc] Support spir-v vector expressions even better It turned out I did need direct vector expression support: the previous commit handled only assignments, not sub-expressions. --- tools/qfcc/include/expr.h | 1 + tools/qfcc/source/expr_vector.c | 20 ++++++++++++++++++++ tools/qfcc/source/target_spirv.c | 21 +++++++++------------ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/tools/qfcc/include/expr.h b/tools/qfcc/include/expr.h index 1c5d8fea9..93de3f56e 100644 --- a/tools/qfcc/include/expr.h +++ b/tools/qfcc/include/expr.h @@ -740,6 +740,7 @@ const expr_t *new_vector_list (const expr_t *e); const expr_t *new_vector_value (const type_t *ele_type, int width, int count, const expr_t **elements, bool implicit); +const expr_t *vector_to_compound (const expr_t *vector); /** Create a new entity constant expression node. diff --git a/tools/qfcc/source/expr_vector.c b/tools/qfcc/source/expr_vector.c index e3fd37040..ad0004e4a 100644 --- a/tools/qfcc/source/expr_vector.c +++ b/tools/qfcc/source/expr_vector.c @@ -145,3 +145,23 @@ new_vector_list (const expr_t *expr_list) list_gather (&vec->vector.list, elements, count); return vec; } + +const expr_t * +vector_to_compound (const expr_t *vector) +{ + if (vector->type != ex_vector) { + internal_error (vector, "not a vector expression"); + } + int count = list_count (&vector->vector.list); + const expr_t *elements[count]; + list_scatter (&vector->vector.list, elements); + + scoped_src_loc (vector); + auto compound = new_compound_init (); + compound->compound.type = vector->vector.type; + for (int i = 0; i < count; i++) { + auto ele = new_element (elements[i], nullptr); + append_init_element (&compound->compound, ele); + } + return compound; +} diff --git a/tools/qfcc/source/target_spirv.c b/tools/qfcc/source/target_spirv.c index 3ebe4f118..4a9d1edc0 100644 --- a/tools/qfcc/source/target_spirv.c +++ b/tools/qfcc/source/target_spirv.c @@ -1147,6 +1147,13 @@ spirv_compound (const expr_t *e, spirvctx_t *ctx) return id; } +static unsigned +spirv_vector (const expr_t *e, spirvctx_t *ctx) +{ + auto compound = vector_to_compound (e); + return spirv_compound (compound, ctx); +} + static unsigned spirv_access_chain (const expr_t *e, spirvctx_t *ctx, const type_t **res_type, const type_t **acc_type) @@ -1518,6 +1525,7 @@ spirv_emit_expr (const expr_t *e, spirvctx_t *ctx) [ex_symbol] = spirv_symbol, [ex_temp] = spirv_temp,//FIXME don't want [ex_value] = spirv_value, + [ex_vector] = spirv_vector, [ex_compound] = spirv_compound, [ex_assign] = spirv_assign, [ex_branch] = spirv_branch, @@ -1844,18 +1852,7 @@ spirv_initialized_temp (const type_t *type, const expr_t *src) static const expr_t * spirv_assign_vector (const expr_t *dst, const expr_t *src) { - int count = list_count (&src->vector.list); - const expr_t *elements[count]; - list_scatter (&src->vector.list, elements); - - scoped_src_loc (src); - auto new = new_compound_init (); - new->compound.type = src->vector.type; - for (int i = 0; i < count; i++) { - auto ele = new_element (elements[i], nullptr); - append_init_element (&new->compound, ele); - } - + auto new = vector_to_compound (src); return new_assign_expr (dst, new);; }