From: 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 ea8af221..c9022c6f 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2610,6 +2610,25 @@ static bool intrinsic_lerp(struct hlsl_ctx *ctx, return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, params->args[0], mul, loc); }
+static bool intrinsic_log10(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; + + if (!elementwise_intrinsic_float_convert_args(ctx, params, loc)) + return false; + + if (!(log = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_LOG2, params->args[0], loc))) + return false; + + /* ln(10) / ln(2) */ + if (!(coeff = hlsl_new_float_constant(ctx, 0.301029995664f, loc))) + return false; + + return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, log, &coeff->node, loc); +} + static bool intrinsic_log2(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -2986,6 +3005,7 @@ intrinsic_functions[] = {"ldexp", 2, true, intrinsic_ldexp}, {"length", 1, true, intrinsic_length}, {"lerp", 3, true, intrinsic_lerp}, + {"log10", 1, true, intrinsic_log10}, {"log2", 1, true, intrinsic_log2}, {"max", 2, true, intrinsic_max}, {"min", 2, true, intrinsic_min}, diff --git a/tests/log.shader_test b/tests/log.shader_test index 9ba0af76..0a99904a 100644 --- a/tests/log.shader_test +++ b/tests/log.shader_test @@ -10,3 +10,16 @@ float4 main() : sv_target uniform 0 float4 2.0 4.0 5.0 0.4 draw quad probe all rgba (1.0, 2.0, 2.32192802, -1.32192802) 1 + +[pixel shader] +uniform float4 x; + +float4 main() : sv_target +{ + return log10(x); +} + +[test] +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