Module: vkd3d Branch: master Commit: a1bd4e080ef5bd0b1bfb073558fb715e9ad54058 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/a1bd4e080ef5bd0b1bfb073558fb71...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Tue Feb 21 23:15:50 2023 +0100
vkd3d-shader/hlsl: Support log() intrinsic.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
---
libs/vkd3d-shader/hlsl.y | 20 ++++++++++++++++++++ tests/log.shader_test | 13 +++++++++++++ 2 files changed, 33 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index e487902e..ce20c00e 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -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}, diff --git a/tests/log.shader_test b/tests/log.shader_test index 0a99904a..b0f405d1 100644 --- a/tests/log.shader_test +++ b/tests/log.shader_test @@ -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