vkd3d-shader/hlsl: Implement hyperbolic sin and cos.

This commit is contained in:
Petrichor Park 2024-02-19 11:25:53 -06:00 committed by Alexandre Julliard
parent 2b7d9790d6
commit c4182cc272
Notes: Alexandre Julliard 2024-04-15 22:22:07 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/740
2 changed files with 54 additions and 6 deletions

View File

@ -3028,6 +3028,46 @@ static bool intrinsic_cos(struct hlsl_ctx *ctx,
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_COS, arg, loc); return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_COS, arg, loc);
} }
static bool write_cosh_or_sinh(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc, bool sinh_mode)
{
struct hlsl_ir_function_decl *func;
struct hlsl_ir_node *arg;
const char *fn_name, *type_name;
char *body;
static const char template[] =
"%s %s(%s x)\n"
"{\n"
" return (exp(x) %s exp(-x)) / 2;\n"
"}\n";
static const char fn_name_sinh[] = "sinh";
static const char fn_name_cosh[] = "cosh";
if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc)))
return false;
type_name = arg->data_type->name;
fn_name = sinh_mode ? fn_name_sinh : fn_name_cosh;
if (!(body = hlsl_sprintf_alloc(ctx, template,
type_name, fn_name, type_name, sinh_mode ? "-" : "+")))
return false;
func = hlsl_compile_internal_function(ctx, fn_name, body);
vkd3d_free(body);
if (!func)
return false;
return add_user_call(ctx, func, params, loc);
}
static bool intrinsic_cosh(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
return write_cosh_or_sinh(ctx, params, loc, false);
}
static bool intrinsic_cross(struct hlsl_ctx *ctx, static bool intrinsic_cross(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)
{ {
@ -3873,6 +3913,12 @@ static bool intrinsic_sin(struct hlsl_ctx *ctx,
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_SIN, arg, loc); return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_SIN, arg, loc);
} }
static bool intrinsic_sinh(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
return write_cosh_or_sinh(ctx, params, loc, true);
}
/* smoothstep(a, b, x) = p^2 (3 - 2p), where p = saturate((x - a)/(b - a)) */ /* smoothstep(a, b, x) = p^2 (3 - 2p), where p = saturate((x - a)/(b - a)) */
static bool intrinsic_smoothstep(struct hlsl_ctx *ctx, static bool intrinsic_smoothstep(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)
@ -4277,6 +4323,7 @@ intrinsic_functions[] =
{"clamp", 3, true, intrinsic_clamp}, {"clamp", 3, true, intrinsic_clamp},
{"clip", 1, true, intrinsic_clip}, {"clip", 1, true, intrinsic_clip},
{"cos", 1, true, intrinsic_cos}, {"cos", 1, true, intrinsic_cos},
{"cosh", 1, true, intrinsic_cosh},
{"cross", 2, true, intrinsic_cross}, {"cross", 2, true, intrinsic_cross},
{"ddx", 1, true, intrinsic_ddx}, {"ddx", 1, true, intrinsic_ddx},
{"ddx_coarse", 1, true, intrinsic_ddx_coarse}, {"ddx_coarse", 1, true, intrinsic_ddx_coarse},
@ -4314,6 +4361,7 @@ intrinsic_functions[] =
{"saturate", 1, true, intrinsic_saturate}, {"saturate", 1, true, intrinsic_saturate},
{"sign", 1, true, intrinsic_sign}, {"sign", 1, true, intrinsic_sign},
{"sin", 1, true, intrinsic_sin}, {"sin", 1, true, intrinsic_sin},
{"sinh", 1, true, intrinsic_sinh},
{"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},

View File

@ -76,7 +76,7 @@ todo(sm<4 | glsl) draw quad
probe all rgba (0, 1000, -1000.0, 0) probe all rgba (0, 1000, -1000.0, 0)
[pixel shader todo] [pixel shader]
uniform float4 a; uniform float4 a;
float4 main() : sv_target float4 main() : sv_target
@ -86,15 +86,15 @@ float4 main() : sv_target
[test] [test]
uniform 0 float4 -6.28318531 -0.88137359 0.88137359 6.28318531 uniform 0 float4 -6.28318531 -0.88137359 0.88137359 6.28318531
todo(sm<6) draw quad todo(glsl) draw quad
probe all rgba (-267.744894, -1.0, 1.0, 267.744894) 2 probe all rgba (-267.744894, -1.0, 1.0, 267.744894) 2
uniform 0 float4 -0.0 0.0 -90.0 90.0 uniform 0 float4 -0.0 0.0 -90.0 90.0
todo(sm<6) draw quad todo(glsl) draw quad
% mingw does not support "inf" for scanf(), but numbers beyond FLOAT_MAX consistently result in inf. % mingw does not support "inf" for scanf(), but numbers beyond FLOAT_MAX consistently result in inf.
probe all rgba (0.0, 0.0, -1.0e39, 1.0e39) 1 probe all rgba (0.0, 0.0, -1.0e39, 1.0e39) 1
[pixel shader todo] [pixel shader]
uniform float4 a; uniform float4 a;
float4 main() : sv_target float4 main() : sv_target
@ -104,10 +104,10 @@ float4 main() : sv_target
[test] [test]
uniform 0 float4 -1.76274717 -1.3169579 1.3169579 1.76274717 uniform 0 float4 -1.76274717 -1.3169579 1.3169579 1.76274717
todo(sm<6) draw quad todo(glsl) draw quad
probe all rgba (3.0, 2.0, 2.0, 3.0) 2 probe all rgba (3.0, 2.0, 2.0, 3.0) 2
uniform 0 float4 -0.0 0.0 -90.0 90.0 uniform 0 float4 -0.0 0.0 -90.0 90.0
todo(sm<6) draw quad todo(glsl) draw quad
probe all rgba (1.0, 1.0, 1.0e39, 1.0e39) 1 probe all rgba (1.0, 1.0, 1.0e39, 1.0e39) 1