mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader/hlsl: Store constant values as an array of unions.
This allows us to more easily manipulate individual elements in a type-agnostic way. For example, it allows easier implementation of constant swizzle folding. Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Matteo Bruni <mbruni@codeweavers.com> Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
committed by
Alexandre Julliard
parent
e2b57f6d2b
commit
b4e301b2d8
@@ -535,7 +535,7 @@ struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned i
|
|||||||
if (!(c = hlsl_alloc(ctx, sizeof(*c))))
|
if (!(c = hlsl_alloc(ctx, sizeof(*c))))
|
||||||
return NULL;
|
return NULL;
|
||||||
init_node(&c->node, HLSL_IR_CONSTANT, ctx->builtin_types.scalar[HLSL_TYPE_UINT], loc);
|
init_node(&c->node, HLSL_IR_CONSTANT, ctx->builtin_types.scalar[HLSL_TYPE_UINT], loc);
|
||||||
c->value.u[0] = n;
|
c->value[0].u = n;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1018,26 +1018,28 @@ static void dump_ir_constant(struct vkd3d_string_buffer *buffer, const struct hl
|
|||||||
vkd3d_string_buffer_printf(buffer, "{");
|
vkd3d_string_buffer_printf(buffer, "{");
|
||||||
for (x = 0; x < type->dimx; ++x)
|
for (x = 0; x < type->dimx; ++x)
|
||||||
{
|
{
|
||||||
|
const union hlsl_constant_value *value = &constant->value[x];
|
||||||
|
|
||||||
switch (type->base_type)
|
switch (type->base_type)
|
||||||
{
|
{
|
||||||
case HLSL_TYPE_BOOL:
|
case HLSL_TYPE_BOOL:
|
||||||
vkd3d_string_buffer_printf(buffer, "%s ", constant->value.b[x] ? "true" : "false");
|
vkd3d_string_buffer_printf(buffer, "%s ", value->b ? "true" : "false");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_DOUBLE:
|
case HLSL_TYPE_DOUBLE:
|
||||||
vkd3d_string_buffer_printf(buffer, "%.16e ", constant->value.d[x]);
|
vkd3d_string_buffer_printf(buffer, "%.16e ", value->d);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_FLOAT:
|
case HLSL_TYPE_FLOAT:
|
||||||
vkd3d_string_buffer_printf(buffer, "%.8e ", constant->value.f[x]);
|
vkd3d_string_buffer_printf(buffer, "%.8e ", value->f);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_INT:
|
case HLSL_TYPE_INT:
|
||||||
vkd3d_string_buffer_printf(buffer, "%d ", constant->value.i[x]);
|
vkd3d_string_buffer_printf(buffer, "%d ", value->i);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_UINT:
|
case HLSL_TYPE_UINT:
|
||||||
vkd3d_string_buffer_printf(buffer, "%u ", constant->value.u[x]);
|
vkd3d_string_buffer_printf(buffer, "%u ", value->u);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@@ -374,14 +374,14 @@ struct hlsl_ir_store
|
|||||||
struct hlsl_ir_constant
|
struct hlsl_ir_constant
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node node;
|
struct hlsl_ir_node node;
|
||||||
union
|
union hlsl_constant_value
|
||||||
{
|
{
|
||||||
unsigned u[4];
|
uint32_t u;
|
||||||
int i[4];
|
int32_t i;
|
||||||
float f[4];
|
float f;
|
||||||
double d[4];
|
double d;
|
||||||
bool b[4];
|
bool b;
|
||||||
} value;
|
} value[4];
|
||||||
struct hlsl_reg reg;
|
struct hlsl_reg reg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -828,20 +828,21 @@ static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node)
|
|||||||
case HLSL_IR_CONSTANT:
|
case HLSL_IR_CONSTANT:
|
||||||
{
|
{
|
||||||
struct hlsl_ir_constant *constant = hlsl_ir_constant(node);
|
struct hlsl_ir_constant *constant = hlsl_ir_constant(node);
|
||||||
|
const union hlsl_constant_value *value = &constant->value[0];
|
||||||
|
|
||||||
switch (constant->node.data_type->base_type)
|
switch (constant->node.data_type->base_type)
|
||||||
{
|
{
|
||||||
case HLSL_TYPE_UINT:
|
case HLSL_TYPE_UINT:
|
||||||
return constant->value.u[0];
|
return value->u;
|
||||||
case HLSL_TYPE_INT:
|
case HLSL_TYPE_INT:
|
||||||
return constant->value.i[0];
|
return value->i;
|
||||||
case HLSL_TYPE_FLOAT:
|
case HLSL_TYPE_FLOAT:
|
||||||
case HLSL_TYPE_HALF:
|
case HLSL_TYPE_HALF:
|
||||||
return constant->value.f[0];
|
return value->f;
|
||||||
case HLSL_TYPE_DOUBLE:
|
case HLSL_TYPE_DOUBLE:
|
||||||
return constant->value.d[0];
|
return value->d;
|
||||||
case HLSL_TYPE_BOOL:
|
case HLSL_TYPE_BOOL:
|
||||||
return constant->value.b[0];
|
return value->b;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -2770,7 +2771,7 @@ primary_expr:
|
|||||||
if (!(c = hlsl_alloc(ctx, sizeof(*c))))
|
if (!(c = hlsl_alloc(ctx, sizeof(*c))))
|
||||||
YYABORT;
|
YYABORT;
|
||||||
init_node(&c->node, HLSL_IR_CONSTANT, ctx->builtin_types.scalar[HLSL_TYPE_FLOAT], @1);
|
init_node(&c->node, HLSL_IR_CONSTANT, ctx->builtin_types.scalar[HLSL_TYPE_FLOAT], @1);
|
||||||
c->value.f[0] = $1;
|
c->value[0].f = $1;
|
||||||
if (!($$ = make_list(ctx, &c->node)))
|
if (!($$ = make_list(ctx, &c->node)))
|
||||||
YYABORT;
|
YYABORT;
|
||||||
}
|
}
|
||||||
@@ -2781,7 +2782,7 @@ primary_expr:
|
|||||||
if (!(c = hlsl_alloc(ctx, sizeof(*c))))
|
if (!(c = hlsl_alloc(ctx, sizeof(*c))))
|
||||||
YYABORT;
|
YYABORT;
|
||||||
init_node(&c->node, HLSL_IR_CONSTANT, ctx->builtin_types.scalar[HLSL_TYPE_INT], @1);
|
init_node(&c->node, HLSL_IR_CONSTANT, ctx->builtin_types.scalar[HLSL_TYPE_INT], @1);
|
||||||
c->value.i[0] = $1;
|
c->value[0].i = $1;
|
||||||
if (!($$ = make_list(ctx, &c->node)))
|
if (!($$ = make_list(ctx, &c->node)))
|
||||||
YYABORT;
|
YYABORT;
|
||||||
}
|
}
|
||||||
@@ -2792,7 +2793,7 @@ primary_expr:
|
|||||||
if (!(c = hlsl_alloc(ctx, sizeof(*c))))
|
if (!(c = hlsl_alloc(ctx, sizeof(*c))))
|
||||||
YYABORT;
|
YYABORT;
|
||||||
init_node(&c->node, HLSL_IR_CONSTANT, ctx->builtin_types.scalar[HLSL_TYPE_BOOL], @1);
|
init_node(&c->node, HLSL_IR_CONSTANT, ctx->builtin_types.scalar[HLSL_TYPE_BOOL], @1);
|
||||||
c->value.b[0] = $1;
|
c->value[0].b = $1;
|
||||||
if (!($$ = make_list(ctx, &c->node)))
|
if (!($$ = make_list(ctx, &c->node)))
|
||||||
YYABORT;
|
YYABORT;
|
||||||
}
|
}
|
||||||
|
@@ -413,12 +413,12 @@ static bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, voi
|
|||||||
{
|
{
|
||||||
case HLSL_TYPE_INT:
|
case HLSL_TYPE_INT:
|
||||||
for (i = 0; i < dimx; ++i)
|
for (i = 0; i < dimx; ++i)
|
||||||
res->value.f[i] = arg1->value.i[i];
|
res->value[i].f = arg1->value[i].i;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_UINT:
|
case HLSL_TYPE_UINT:
|
||||||
for (i = 0; i < dimx; ++i)
|
for (i = 0; i < dimx; ++i)
|
||||||
res->value.f[i] = arg1->value.u[i];
|
res->value[i].f = arg1->value[i].u;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -443,17 +443,17 @@ static bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, voi
|
|||||||
{
|
{
|
||||||
case HLSL_OP1_NEG:
|
case HLSL_OP1_NEG:
|
||||||
for (i = 0; i < instr->data_type->dimx; ++i)
|
for (i = 0; i < instr->data_type->dimx; ++i)
|
||||||
res->value.u[i] = -arg1->value.u[i];
|
res->value[i].u = -arg1->value[i].u;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_OP2_ADD:
|
case HLSL_OP2_ADD:
|
||||||
for (i = 0; i < instr->data_type->dimx; ++i)
|
for (i = 0; i < instr->data_type->dimx; ++i)
|
||||||
res->value.u[i] = arg1->value.u[i] + arg2->value.u[i];
|
res->value[i].u = arg1->value[i].u + arg2->value[i].u;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_OP2_MUL:
|
case HLSL_OP2_MUL:
|
||||||
for (i = 0; i < instr->data_type->dimx; ++i)
|
for (i = 0; i < instr->data_type->dimx; ++i)
|
||||||
res->value.u[i] = arg1->value.u[i] * arg2->value.u[i];
|
res->value[i].u = arg1->value[i].u * arg2->value[i].u;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -920,28 +920,30 @@ static void allocate_const_registers_recurse(struct hlsl_ctx *ctx, struct list *
|
|||||||
{
|
{
|
||||||
for (x = 0, i = 0; x < 4; ++x)
|
for (x = 0, i = 0; x < 4; ++x)
|
||||||
{
|
{
|
||||||
|
const union hlsl_constant_value *value;
|
||||||
float f;
|
float f;
|
||||||
|
|
||||||
if (!(writemask & (1u << x)))
|
if (!(writemask & (1u << x)))
|
||||||
continue;
|
continue;
|
||||||
|
value = &constant->value[i++];
|
||||||
|
|
||||||
switch (type->base_type)
|
switch (type->base_type)
|
||||||
{
|
{
|
||||||
case HLSL_TYPE_BOOL:
|
case HLSL_TYPE_BOOL:
|
||||||
f = constant->value.b[i++];
|
f = value->b;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_FLOAT:
|
case HLSL_TYPE_FLOAT:
|
||||||
case HLSL_TYPE_HALF:
|
case HLSL_TYPE_HALF:
|
||||||
f = constant->value.f[i++];
|
f = value->f;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_INT:
|
case HLSL_TYPE_INT:
|
||||||
f = constant->value.i[i++];
|
f = value->i;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_UINT:
|
case HLSL_TYPE_UINT:
|
||||||
f = constant->value.u[i++];
|
f = value->u;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_DOUBLE:
|
case HLSL_TYPE_DOUBLE:
|
||||||
@@ -1208,7 +1210,7 @@ struct hlsl_reg hlsl_reg_from_deref(const struct hlsl_deref *deref, const struct
|
|||||||
ret.allocated = var->reg.allocated;
|
ret.allocated = var->reg.allocated;
|
||||||
ret.id = var->reg.id;
|
ret.id = var->reg.id;
|
||||||
if (offset_node)
|
if (offset_node)
|
||||||
offset = hlsl_ir_constant(offset_node)->value.u[0];
|
offset = hlsl_ir_constant(offset_node)->value[0].u;
|
||||||
ret.id += offset / 4;
|
ret.id += offset / 4;
|
||||||
|
|
||||||
if (type_is_single_reg(var->data_type))
|
if (type_is_single_reg(var->data_type))
|
||||||
|
@@ -962,7 +962,7 @@ static void write_sm4_constant(struct hlsl_ctx *ctx,
|
|||||||
instr.srcs[0].reg.idx[0] = constant->reg.id;
|
instr.srcs[0].reg.idx[0] = constant->reg.id;
|
||||||
instr.srcs[0].reg.idx_count = 1;
|
instr.srcs[0].reg.idx_count = 1;
|
||||||
for (i = 0; i < dimx; ++i)
|
for (i = 0; i < dimx; ++i)
|
||||||
instr.srcs[0].reg.immconst_uint[i] = constant->value.u[i];
|
instr.srcs[0].reg.immconst_uint[i] = constant->value[i].u;
|
||||||
instr.src_count = 1,
|
instr.src_count = 1,
|
||||||
|
|
||||||
write_sm4_instruction(buffer, &instr);
|
write_sm4_instruction(buffer, &instr);
|
||||||
|
Reference in New Issue
Block a user