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 c8812892..0991a01f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -118,6 +118,7 @@ vkd3d_shader_tests = \ tests/hlsl-vector-indexing.shader_test \ tests/hlsl-vector-indexing-uniform.shader_test \ tests/lit.shader_test \ + tests/log.shader_test \ tests/logic-operations.shader_test \ tests/majority-syntax.shader_test \ tests/math.shader_test \ diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index e0e0e5ce..fa7a07ab 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2772,6 +2772,15 @@ static bool intrinsic_lit(struct hlsl_ctx *ctx, return true; }
+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) { @@ -3151,6 +3160,7 @@ intrinsic_functions[] = {"length", 1, true, intrinsic_length}, {"lerp", 3, true, intrinsic_lerp}, {"lit", 3, true, intrinsic_lit}, + {"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