From: Nikolay Sivov nsivov@codeweavers.com
--- Makefile.am | 1 + libs/vkd3d-shader/hlsl.y | 10 ++++++++++ tests/log.shader_test | 12 ++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 tests/log.shader_test
diff --git a/Makefile.am b/Makefile.am index f9199472..8ed816f6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -115,6 +115,7 @@ vkd3d_shader_tests = \ tests/hlsl-transpose.shader_test \ tests/hlsl-vector-indexing.shader_test \ tests/hlsl-vector-indexing-uniform.shader_test \ + tests/log.shader_test \ tests/logic-operations.shader_test \ tests/math.shader_test \ tests/matrix-semantics.shader_test \ diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index d5e2b2a9..ea8af221 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2610,6 +2610,15 @@ 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_log2(struct hlsl_ctx *ctx, + const struct parse_initializer *params, const struct vkd3d_shader_location *loc) +{ + if (!elementwise_intrinsic_float_convert_args(ctx, params, loc)) + return false; + + return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_LOG2, params->args[0], loc); +} + static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -2977,6 +2986,7 @@ intrinsic_functions[] = {"ldexp", 2, true, intrinsic_ldexp}, {"length", 1, true, intrinsic_length}, {"lerp", 3, true, intrinsic_lerp}, + {"log2", 1, true, intrinsic_log2}, {"max", 2, true, intrinsic_max}, {"min", 2, true, intrinsic_min}, {"mul", 2, true, intrinsic_mul}, diff --git a/tests/log.shader_test b/tests/log.shader_test new file mode 100644 index 00000000..9ba0af76 --- /dev/null +++ b/tests/log.shader_test @@ -0,0 +1,12 @@ +[pixel shader] +uniform float4 x; + +float4 main() : sv_target +{ + return log2(x); +} + +[test] +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