vkd3d-shader/hlsl: Support log() intrinsic.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov 2023-02-21 23:15:50 +01:00 committed by Alexandre Julliard
parent 210caa931d
commit a1bd4e080e
Notes: Alexandre Julliard 2023-04-13 23:19:56 +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/89
2 changed files with 33 additions and 0 deletions

View File

@ -2843,6 +2843,25 @@ static bool intrinsic_lit(struct hlsl_ctx *ctx,
return true;
}
static bool intrinsic_log(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
struct hlsl_ir_constant *coeff;
struct hlsl_ir_node *log, *arg;
if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc)))
return false;
if (!(log = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_LOG2, arg, loc)))
return false;
/* ln(2) */
if (!(coeff = hlsl_new_float_constant(ctx, 0.69314718055f, loc)))
return false;
return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, log, &coeff->node, loc);
}
static bool intrinsic_log10(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
@ -3330,6 +3349,7 @@ intrinsic_functions[] =
{"length", 1, true, intrinsic_length},
{"lerp", 3, true, intrinsic_lerp},
{"lit", 3, true, intrinsic_lit},
{"log", 1, true, intrinsic_log},
{"log10", 1, true, intrinsic_log10},
{"log2", 1, true, intrinsic_log2},
{"max", 2, true, intrinsic_max},

View File

@ -23,3 +23,16 @@ float4 main() : sv_target
uniform 0 float4 10.0 100.0 1.0 0.1
draw quad
probe all rgba (1.0, 2.0, 0.0, -1.0) 1
[pixel shader]
uniform float4 x;
float4 main() : sv_target
{
return log(x);
}
[test]
uniform 0 float4 3.0 10.0 1.0 0.1
draw quad
probe all rgba (1.0986123, 2.302585, 0.0, -2.302585) 2