vkd3d-shader/hlsl: Implement intrinsic tan.

This commit also extends the trigonometry tests a little bit to make
sure that tan works right.
This commit is contained in:
Petrichor Park 2023-08-31 10:53:10 -05:00 committed by Alexandre Julliard
parent 6ec5e5bf54
commit 976fd67f51
Notes: Alexandre Julliard 2023-09-25 22:27:36 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Francisco Casas (@fcasas)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/321
2 changed files with 48 additions and 17 deletions

View File

@ -3423,6 +3423,20 @@ static bool intrinsic_step(struct hlsl_ctx *ctx,
return !!add_implicit_conversion(ctx, params->instrs, ge, type, loc); return !!add_implicit_conversion(ctx, params->instrs, ge, type, loc);
} }
static bool intrinsic_tan(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
struct hlsl_ir_node *arg = params->args[0], *sin, *cos;
if (!(sin = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_SIN, arg, loc)))
return false;
if (!(cos = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_COS, arg, loc)))
return false;
return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_DIV, sin, cos, loc);
}
static bool intrinsic_tex(struct hlsl_ctx *ctx, const struct parse_initializer *params, static bool intrinsic_tex(struct hlsl_ctx *ctx, const struct parse_initializer *params,
const struct vkd3d_shader_location *loc, const char *name, enum hlsl_sampler_dim dim) const struct vkd3d_shader_location *loc, const char *name, enum hlsl_sampler_dim dim)
{ {
@ -3697,6 +3711,7 @@ intrinsic_functions[] =
{"smoothstep", 3, true, intrinsic_smoothstep}, {"smoothstep", 3, true, intrinsic_smoothstep},
{"sqrt", 1, true, intrinsic_sqrt}, {"sqrt", 1, true, intrinsic_sqrt},
{"step", 2, true, intrinsic_step}, {"step", 2, true, intrinsic_step},
{"tan", 1, true, intrinsic_tan},
{"tex1D", -1, false, intrinsic_tex1D}, {"tex1D", -1, false, intrinsic_tex1D},
{"tex2D", -1, false, intrinsic_tex2D}, {"tex2D", -1, false, intrinsic_tex2D},
{"tex3D", -1, false, intrinsic_tex3D}, {"tex3D", -1, false, intrinsic_tex3D},

View File

@ -8,27 +8,27 @@ void main(out float tex : texcoord, inout float4 pos : sv_position)
float4 main(float tex : texcoord) : sv_target float4 main(float tex : texcoord) : sv_target
{ {
tex = floor(tex + 0.25); tex = floor(tex + 0.25);
return float4(sin(tex), cos(tex), 0, 0); return float4(sin(tex), cos(tex), tan(tex), 0);
} }
[test] [test]
draw quad draw quad
probe ( 0, 0) rgba ( 0.00000000, 1.00000000, 0.0, 0.0) probe ( 0, 0) rgba ( 0.00000000, 1.00000000, 0.00000000, 0.0)
probe ( 1, 0) rgba ( 0.84147098, 0.54030231, 0.0, 0.0) 1024 probe ( 1, 0) rgba ( 0.84147098, 0.54030231, 1.55740772, 0.0) 1024
probe ( 2, 0) rgba ( 0.90929743, -0.41614684, 0.0, 0.0) 1024 probe ( 2, 0) rgba ( 0.90929743, -0.41614684, -2.18503986, 0.0) 1024
probe ( 3, 0) rgba ( 0.14112001, -0.98999250, 0.0, 0.0) 1024 probe ( 3, 0) rgba ( 0.14112001, -0.98999250, -0.14254654, 0.0) 1024
probe ( 4, 0) rgba (-0.75680250, -0.65364362, 0.0, 0.0) 1024 probe ( 4, 0) rgba (-0.75680250, -0.65364362, 1.15782128, 0.0) 1024
probe ( 5, 0) rgba (-0.95892427, 0.28366219, 0.0, 0.0) 1024 probe ( 5, 0) rgba (-0.95892427, 0.28366219, -3.38051501, 0.0) 1024
probe ( 6, 0) rgba (-0.27941550, 0.96017029, 0.0, 0.0) 1024 probe ( 6, 0) rgba (-0.27941550, 0.96017029, -0.29100619, 0.0) 1024
probe ( 7, 0) rgba ( 0.65698660, 0.75390225, 0.0, 0.0) 1024 probe ( 7, 0) rgba ( 0.65698660, 0.75390225, 0.87144798, 0.0) 1024
probe ( 8, 0) rgba ( 0.98935825, -0.14550003, 0.0, 0.0) 1024 probe ( 8, 0) rgba ( 0.98935825, -0.14550003, -6.79971146, 0.0) 1024
probe ( 9, 0) rgba ( 0.41211849, -0.91113026, 0.0, 0.0) 1024 probe ( 9, 0) rgba ( 0.41211849, -0.91113026, -0.45231566, 0.0) 1024
probe (10, 0) rgba (-0.54402111, -0.83907153, 0.0, 0.0) 1024 probe (10, 0) rgba (-0.54402111, -0.83907153, 0.64836083, 0.0) 1024
probe (11, 0) rgba (-0.99999021, 0.00442570, 0.0, 0.0) 2048 probe (11, 0) rgba (-0.99999021, 0.00442570, -225.95084645, 0.0) 2048
probe (12, 0) rgba (-0.53657292, 0.84385396, 0.0, 0.0) 1024 probe (12, 0) rgba (-0.53657292, 0.84385396, -0.63585993, 0.0) 1024
probe (13, 0) rgba ( 0.42016704, 0.90744678, 0.0, 0.0) 1024 probe (13, 0) rgba ( 0.42016704, 0.90744678, 0.46302113, 0.0) 1024
probe (14, 0) rgba ( 0.99060736, 0.13673722, 0.0, 0.0) 1024 probe (14, 0) rgba ( 0.99060736, 0.13673722, 7.24460662, 0.0) 1024
probe (15, 0) rgba ( 0.65028784, -0.75968791, 0.0, 0.0) 1024 probe (15, 0) rgba ( 0.65028784, -0.75968791, -0.85599340, 0.0) 1024
[pixel shader] [pixel shader]
@ -57,3 +57,19 @@ float4 main() : sv_target
uniform 0 float4 0.0 0.78539816 1.57079632 2.35619449 uniform 0 float4 0.0 0.78539816 1.57079632 2.35619449
draw quad draw quad
probe all rgba (1000.0, 707.0, -0.0, -707.0) probe all rgba (1000.0, 707.0, -0.0, -707.0)
[pixel shader]
uniform float4 a;
float4 main() : sv_target
{
return round(1000 * tan(a));
}
[test]
% tan(pi/2) is an asymtote and therefore undefined
% so check 0, pi/4, 3pi/4, pi
uniform 0 float4 0.0 0.78539816 2.35619449 3.14159265
draw quad
probe all rgba (0, 1000, -1000.0, 0)