[PATCH vkd3d 07/17] vkd3d-shader/hlsl: Lower narrowing casts to swizzles.
Giovanni Mascellani
gmascellani at codeweavers.com
Thu Dec 2 10:07:41 CST 2021
Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
---
With the same comments as 6/17.
On 01/12/21 17:14, Matteo Bruni wrote:
> From: Zebediah Figura <zfigura at codeweavers.com>
>
> Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
> ---
> changelog: Create a new cast instruction instead of reusing the
> existing one.
>
> Makefile.am | 1 -
> libs/vkd3d-shader/hlsl_codegen.c | 37 ++++++++++++++++++++++++++++++++
> libs/vkd3d-shader/hlsl_sm4.c | 15 ++++++-------
> 3 files changed, 43 insertions(+), 10 deletions(-)
>
> diff --git a/Makefile.am b/Makefile.am
> index 4010533a..88bdc0ee 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -290,7 +290,6 @@ XFAIL_TESTS = \
> tests/conditional.shader_test \
> tests/hlsl-array-dimension.shader_test \
> tests/hlsl-bool-cast.shader_test \
> - tests/hlsl-cross.shader_test \
> tests/hlsl-duplicate-modifiers.shader_test \
> tests/hlsl-for.shader_test \
> tests/hlsl-function-overload.shader_test \
> diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
> index 3cc41d4e..64450c76 100644
> --- a/libs/vkd3d-shader/hlsl_codegen.c
> +++ b/libs/vkd3d-shader/hlsl_codegen.c
> @@ -796,6 +796,42 @@ static bool split_struct_copies(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr
> return true;
> }
>
> +static bool lower_narrowing_casts(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
> +{
> + const struct hlsl_type *src_type, *dst_type;
> + struct hlsl_type *dst_vector_type;
> + struct hlsl_ir_expr *cast;
> +
> + if (instr->type != HLSL_IR_EXPR)
> + return false;
> + cast = hlsl_ir_expr(instr);
> + src_type = cast->operands[0].node->data_type;
> + dst_type = cast->node.data_type;
> +
> + if (cast->op == HLSL_OP1_CAST
> + && src_type->type <= HLSL_CLASS_VECTOR && dst_type->type <= HLSL_CLASS_VECTOR
> + && dst_type->dimx < src_type->dimx)
> + {
> + struct hlsl_ir_swizzle *swizzle;
> + struct hlsl_ir_expr *new_cast;
> +
> + dst_vector_type = hlsl_get_vector_type(ctx, dst_type->base_type, src_type->dimx);
> + /* We need to preserve the cast since it might be doing more than just
> + * narrowing the vector. */
> + if (!(new_cast = hlsl_new_cast(ctx, cast->operands[0].node, dst_vector_type, &cast->node.loc)))
> + return false;
> + list_add_after(&cast->node.entry, &new_cast->node.entry);
> + if (!(swizzle = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(X, Y, Z, W), dst_type->dimx, &new_cast->node, &cast->node.loc)))
> + return false;
> + list_add_after(&new_cast->node.entry, &swizzle->node.entry);
> +
> + replace_node(&cast->node, &swizzle->node);
> + return true;
> + }
> +
> + return false;
> +}
> +
> static bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
> {
> struct hlsl_ir_constant *arg1, *arg2 = NULL, *res;
> @@ -1849,6 +1885,7 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
> progress |= transform_ir(ctx, split_struct_copies, body, NULL);
> }
> while (progress);
> + transform_ir(ctx, lower_narrowing_casts, body, NULL);
> do
> {
> progress = transform_ir(ctx, fold_constants, body, NULL);
> diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c
> index 1c0fea53..a75abbc0 100644
> --- a/libs/vkd3d-shader/hlsl_sm4.c
> +++ b/libs/vkd3d-shader/hlsl_sm4.c
> @@ -1298,9 +1298,8 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
> {
> const struct hlsl_type *src_type = arg1->data_type;
>
> - /* Narrowing casts need to be lowered. */
> - if (src_type->dimx != expr->node.data_type->dimx)
> - hlsl_fixme(ctx, expr->node.loc, "Narrowing cast.\n");
> + /* Narrowing casts were already lowered. */
> + assert(src_type->dimx == expr->node.data_type->dimx);
>
> switch (src_type->base_type)
> {
> @@ -1388,9 +1387,8 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
> {
> const struct hlsl_type *src_type = arg1->data_type;
>
> - /* Narrowing casts need to be lowered. */
> - if (src_type->dimx != expr->node.data_type->dimx)
> - hlsl_fixme(ctx, expr->node.loc, "Narrowing cast.");
> + /* Narrowing casts were already lowered. */
> + assert(src_type->dimx == expr->node.data_type->dimx);
>
> switch (src_type->base_type)
> {
> @@ -1433,9 +1431,8 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
> {
> const struct hlsl_type *src_type = arg1->data_type;
>
> - /* Narrowing casts need to be lowered. */
> - if (src_type->dimx != expr->node.data_type->dimx)
> - hlsl_fixme(ctx, expr->node.loc, "SM4 narrowing cast.\n");
> + /* Narrowing casts were already lowered. */
> + assert(src_type->dimx == expr->node.data_type->dimx);
>
> switch (src_type->base_type)
> {
>
More information about the wine-devel
mailing list