Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- Makefile.am | 1 - libs/vkd3d-shader/hlsl_codegen.c | 32 ++++++++++++++++++++++++++++++++ libs/vkd3d-shader/hlsl_sm4.c | 15 ++++++--------- 3 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/Makefile.am b/Makefile.am index 4010533af..88bdc0ee4 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 b69df47a0..e61c6de6f 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -653,6 +653,37 @@ 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_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; + + if (!(swizzle = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(X, Y, Z, W), dst_type->dimx, &cast->node, &cast->node.loc))) + return false; + list_add_after(&cast->node.entry, &swizzle->node.entry); + + cast->node.data_type = hlsl_get_vector_type(ctx, dst_type->base_type, src_type->dimx); + replace_node(&cast->node, &swizzle->node); + hlsl_src_remove(&swizzle->val); + hlsl_src_from_node(&swizzle->val, &cast->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; @@ -1706,6 +1737,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 c36aa5618..ed6de2a11 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) {