From: Nikolay Sivov nsivov@codeweavers.com
--- libs/vkd3d-shader/hlsl_sm1.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl_sm1.c b/libs/vkd3d-shader/hlsl_sm1.c index ba22925e..71f7d5f6 100644 --- a/libs/vkd3d-shader/hlsl_sm1.c +++ b/libs/vkd3d-shader/hlsl_sm1.c @@ -632,13 +632,14 @@ static void write_sm1_expr(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *b break;
case HLSL_OP1_RCP: + case HLSL_OP1_RSQ: for (i = 0; i < instr->data_type->dimx; ++i) { struct hlsl_reg src = arg1->reg, dst = instr->reg;
src.writemask = hlsl_combine_writemasks(src.writemask, 1u << i); dst.writemask = hlsl_combine_writemasks(dst.writemask, 1u << i); - write_sm1_unary_op(ctx, buffer, D3DSIO_RCP, &dst, &src, 0); + write_sm1_unary_op(ctx, buffer, expr->op == HLSL_OP1_RCP ? D3DSIO_RCP : D3DSIO_RSQ, &dst, &src, 0); } break;
From: Nikolay Sivov nsivov@codeweavers.com
--- libs/vkd3d-shader/hlsl_codegen.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 9b644d1b..5163d913 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1345,6 +1345,27 @@ static bool lower_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, voi return true; }
+/* Lower SQRT to RSQ + RCP. */ +static bool lower_sqrt(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) +{ + struct hlsl_ir_expr *expr; + struct hlsl_ir_node *rsq; + + if (instr->type != HLSL_IR_EXPR) + return false; + expr = hlsl_ir_expr(instr); + if (expr->op != HLSL_OP1_SQRT) + return false; + + if (!(rsq = hlsl_new_unary_expr(ctx, HLSL_OP1_RSQ, expr->operands[0].node, instr->loc))) + return false; + list_add_before(&expr->node.entry, &rsq->entry); + expr->op = HLSL_OP1_RCP; + hlsl_src_remove(&expr->operands[0]); + hlsl_src_from_node(&expr->operands[0], rsq); + return true; +} + static bool lower_casts_to_bool(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) { struct hlsl_type *type = instr->data_type, *arg_type; @@ -2755,7 +2776,10 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry while (progress);
if (profile->major_version < 4) + { transform_ir(ctx, lower_division, body, NULL); + transform_ir(ctx, lower_sqrt, body, NULL); + }
transform_ir(ctx, validate_static_object_references, body, NULL);
This merge request was approved by Zebediah Figura.
This merge request was approved by Henri Verbeet.
This merge request was approved by Giovanni Mascellani.