vkd3d-shader/hlsl: Implement the mad() intrinsic.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov 2024-09-04 13:19:16 +02:00 committed by Henri Verbeet
parent 75299c04fd
commit de6abd964e
Notes: Henri Verbeet 2024-09-10 21:56:01 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1036
3 changed files with 37 additions and 5 deletions

View File

@ -4152,6 +4152,20 @@ static bool intrinsic_log2(struct hlsl_ctx *ctx,
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_LOG2, arg, loc); return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_LOG2, arg, loc);
} }
static bool intrinsic_mad(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {0};
if (!elementwise_intrinsic_convert_args(ctx, params, loc))
return false;
args[0] = params->args[0];
args[1] = params->args[1];
args[2] = params->args[2];
return add_expr(ctx, params->instrs, HLSL_OP3_MAD, args, args[0]->data_type, loc);
}
static bool intrinsic_max(struct hlsl_ctx *ctx, static bool intrinsic_max(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc) const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{ {
@ -5053,6 +5067,7 @@ intrinsic_functions[] =
{"log", 1, true, intrinsic_log}, {"log", 1, true, intrinsic_log},
{"log10", 1, true, intrinsic_log10}, {"log10", 1, true, intrinsic_log10},
{"log2", 1, true, intrinsic_log2}, {"log2", 1, true, intrinsic_log2},
{"mad", 3, true, intrinsic_mad},
{"max", 2, true, intrinsic_max}, {"max", 2, true, intrinsic_max},
{"min", 2, true, intrinsic_min}, {"min", 2, true, intrinsic_min},
{"mul", 2, true, intrinsic_mul}, {"mul", 2, true, intrinsic_mul},

View File

@ -5580,6 +5580,23 @@ static void write_sm4_expr(const struct tpf_writer *tpf, const struct hlsl_ir_ex
write_sm4_ternary_op(tpf, VKD3D_SM4_OP_MOVC, &expr->node, arg1, arg2, arg3); write_sm4_ternary_op(tpf, VKD3D_SM4_OP_MOVC, &expr->node, arg1, arg2, arg3);
break; break;
case HLSL_OP3_MAD:
switch (dst_type->e.numeric.type)
{
case HLSL_TYPE_FLOAT:
write_sm4_ternary_op(tpf, VKD3D_SM4_OP_MAD, &expr->node, arg1, arg2, arg3);
break;
case HLSL_TYPE_INT:
case HLSL_TYPE_UINT:
write_sm4_ternary_op(tpf, VKD3D_SM4_OP_IMAD, &expr->node, arg1, arg2, arg3);
break;
default:
hlsl_fixme(tpf->ctx, &expr->node.loc, "SM4 %s negation expression.", dst_type_string->buffer);
}
break;
default: default:
hlsl_fixme(tpf->ctx, &expr->node.loc, "SM4 %s expression.", debug_hlsl_expr_op(expr->op)); hlsl_fixme(tpf->ctx, &expr->node.loc, "SM4 %s expression.", debug_hlsl_expr_op(expr->op));
} }

View File

@ -91,7 +91,7 @@ uniform 0 float4 1.0 0.0 0.0 0.0
todo(glsl) draw quad todo(glsl) draw quad
probe (0, 0) rgba (1e99, 1e99, 1e99, 1e99) probe (0, 0) rgba (1e99, 1e99, 1e99, 1e99)
[pixel shader todo] [pixel shader]
uniform float4 a, b, c; uniform float4 a, b, c;
float4 main() : sv_target float4 main() : sv_target
@ -103,11 +103,11 @@ float4 main() : sv_target
uniform 0 float4 1.00000007 -42.1 4.0 45.0 uniform 0 float4 1.00000007 -42.1 4.0 45.0
uniform 4 float4 1.625 -5.0 4.125 5.0 uniform 4 float4 1.625 -5.0 4.125 5.0
uniform 8 float4 1.00000007 -1.0 0.5 -0.5 uniform 8 float4 1.00000007 -1.0 0.5 -0.5
todo(sm<6) draw quad todo(glsl) draw quad
probe (0, 0) rgba (2.62500024, 209.5, 17.0, 224.5) 1 probe (0, 0) rgba (2.62500024, 209.5, 17.0, 224.5) 1
% precise mad() is not allowed to fuse, even though unfused is less precise. % precise mad() is not allowed to fuse, even though unfused is less precise.
[pixel shader todo] [pixel shader]
uniform float4 a, b, c; uniform float4 a, b, c;
float4 main() : sv_target float4 main() : sv_target
@ -120,8 +120,8 @@ float4 main() : sv_target
uniform 0 float4 1.00000007 -42.1 4.0 45.0 uniform 0 float4 1.00000007 -42.1 4.0 45.0
uniform 4 float4 1.625 -5.0 4.125 5.0 uniform 4 float4 1.625 -5.0 4.125 5.0
uniform 8 float4 1.00000007 -1.0 0.5 -0.5 uniform 8 float4 1.00000007 -1.0 0.5 -0.5
todo(sm<6) draw quad todo(glsl) draw quad
probe (0, 0) rgba (2.62500048, 209.5, 17.0, 224.5) probe (0, 0) rgba (2.62500048, 209.5, 17.0, 224.5) 1
[require] [require]
shader model >= 5.0 shader model >= 5.0