mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader/hlsl: Fold constant swizzles.
Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
committed by
Alexandre Julliard
parent
7682da58a8
commit
0ddaa80616
@@ -800,7 +800,8 @@ bool hlsl_offset_from_deref(struct hlsl_ctx *ctx, const struct hlsl_deref *deref
|
|||||||
unsigned int hlsl_offset_from_deref_safe(struct hlsl_ctx *ctx, const struct hlsl_deref *deref);
|
unsigned int hlsl_offset_from_deref_safe(struct hlsl_ctx *ctx, const struct hlsl_deref *deref);
|
||||||
struct hlsl_reg hlsl_reg_from_deref(struct hlsl_ctx *ctx, const struct hlsl_deref *deref);
|
struct hlsl_reg hlsl_reg_from_deref(struct hlsl_ctx *ctx, const struct hlsl_deref *deref);
|
||||||
|
|
||||||
bool hlsl_fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context);
|
bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context);
|
||||||
|
bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context);
|
||||||
|
|
||||||
bool hlsl_sm1_register_from_semantic(struct hlsl_ctx *ctx, const struct hlsl_semantic *semantic,
|
bool hlsl_sm1_register_from_semantic(struct hlsl_ctx *ctx, const struct hlsl_semantic *semantic,
|
||||||
bool output, D3DSHADER_PARAM_REGISTER_TYPE *type, unsigned int *reg);
|
bool output, D3DSHADER_PARAM_REGISTER_TYPE *type, unsigned int *reg);
|
||||||
|
@@ -1946,7 +1946,8 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
|
|||||||
transform_ir(ctx, lower_casts_to_bool, body, NULL);
|
transform_ir(ctx, lower_casts_to_bool, body, NULL);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
progress = transform_ir(ctx, hlsl_fold_constants, body, NULL);
|
progress = transform_ir(ctx, hlsl_fold_constant_exprs, body, NULL);
|
||||||
|
progress |= transform_ir(ctx, hlsl_fold_constant_swizzles, body, NULL);
|
||||||
progress |= copy_propagation_execute(ctx, body);
|
progress |= copy_propagation_execute(ctx, body);
|
||||||
progress |= transform_ir(ctx, remove_trivial_swizzles, body, NULL);
|
progress |= transform_ir(ctx, remove_trivial_swizzles, body, NULL);
|
||||||
}
|
}
|
||||||
|
@@ -369,7 +369,7 @@ static bool fold_mod(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hlsl_fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_constant *arg1, *arg2 = NULL, *res;
|
struct hlsl_ir_constant *arg1, *arg2 = NULL, *res;
|
||||||
struct hlsl_ir_expr *expr;
|
struct hlsl_ir_expr *expr;
|
||||||
@@ -447,3 +447,32 @@ bool hlsl_fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void
|
|||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||||
|
{
|
||||||
|
struct hlsl_ir_constant *value, *res;
|
||||||
|
struct hlsl_ir_swizzle *swizzle;
|
||||||
|
unsigned int i, swizzle_bits;
|
||||||
|
|
||||||
|
if (instr->type != HLSL_IR_SWIZZLE)
|
||||||
|
return false;
|
||||||
|
swizzle = hlsl_ir_swizzle(instr);
|
||||||
|
if (swizzle->val.node->type != HLSL_IR_CONSTANT)
|
||||||
|
return false;
|
||||||
|
value = hlsl_ir_constant(swizzle->val.node);
|
||||||
|
|
||||||
|
if (!(res = hlsl_alloc(ctx, sizeof(*res))))
|
||||||
|
return false;
|
||||||
|
init_node(&res->node, HLSL_IR_CONSTANT, instr->data_type, instr->loc);
|
||||||
|
|
||||||
|
swizzle_bits = swizzle->swizzle;
|
||||||
|
for (i = 0; i < swizzle->node.data_type->dimx; ++i)
|
||||||
|
{
|
||||||
|
res->value[i] = value->value[swizzle_bits & 3];
|
||||||
|
swizzle_bits >>= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
list_add_before(&swizzle->node.entry, &res->node.entry);
|
||||||
|
hlsl_replace_node(&swizzle->node, &res->node);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user