0
0
Fork 0
mirror of https://git.code.sf.net/p/quake/quakeforge synced 2025-04-11 11:51:50 +00:00

[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.
This commit is contained in:
Bill Currie 2024-11-18 15:47:22 +09:00
parent 0771d6b3be
commit 3dc22d8cd6
3 changed files with 30 additions and 12 deletions
tools/qfcc

View file

@ -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.

View file

@ -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;
}

View file

@ -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);;
}