From: Giovanni Mascellani Subject: Re: [PATCH v4 vkd3d 2/3] vkd3d-shader/hlsl: Cast saturate() input to float. Message-Id: <722ab541-a7ad-eb2b-8462-f01e49cdb2c3@codeweavers.com> Date: Fri, 7 Jan 2022 17:13:11 +0100 In-Reply-To: <20220107140521.251058-2-nsivov@codeweavers.com> References: <20220107140521.251058-1-nsivov@codeweavers.com> <20220107140521.251058-2-nsivov@codeweavers.com> Signed-off-by: Giovanni Mascellani On 07/01/22 15:05, Nikolay Sivov wrote: > Signed-off-by: Nikolay Sivov > --- > libs/vkd3d-shader/hlsl.y | 7 ++++++- > tests/saturate.shader_test | 11 +++++++++++ > 2 files changed, 17 insertions(+), 1 deletion(-) > > diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y > index 6c285c3..94eaec4 100644 > --- a/libs/vkd3d-shader/hlsl.y > +++ b/libs/vkd3d-shader/hlsl.y > @@ -1698,7 +1698,12 @@ static bool intrinsic_round(struct hlsl_ctx *ctx, > static bool intrinsic_saturate(struct hlsl_ctx *ctx, > const struct parse_initializer *params, const struct vkd3d_shader_location *loc) > { > - return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_SAT, params->args[0], loc); > + struct hlsl_ir_node *arg; > + > + if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) > + return false; > + > + return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_SAT, arg, loc); > } > > static const struct intrinsic_function > diff --git a/tests/saturate.shader_test b/tests/saturate.shader_test > index 0a954e7..e99df5b 100644 > --- a/tests/saturate.shader_test > +++ b/tests/saturate.shader_test > @@ -8,3 +8,14 @@ float4 main(uniform float2 u) : sv_target > uniform 0 float4 0.7 -0.1 0.0 0.0 > draw quad > probe all rgba (0.7, 0.0, 1.0, 0.0) > + > +[pixel shader] > +float4 main(uniform int4 u) : sv_target > +{ > + return saturate(u); > +} > + > +[test] > +uniform 0 int4 -2 0 2 -1 > +draw quad > +probe all rgba (0.0, 0.0, 1.0, 0.0)