Module: vkd3d Branch: master Commit: 49b63fbeba6d0665fa8ced7d2e2dd4376c98deb9 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/49b63fbeba6d0665fa8ced7d2e2dd4...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Tue Feb 21 23:13:24 2023 +0100
vkd3d-shader/hlsl: Support log2() intrinsic.
---
Makefile.am | 1 + libs/vkd3d-shader/hlsl.y | 12 ++++++++++++ tests/log.shader_test | 12 ++++++++++++ 3 files changed, 25 insertions(+)
diff --git a/Makefile.am b/Makefile.am index 48991982..a7abd56a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -122,6 +122,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 3873a939..f2990e6f 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2843,6 +2843,17 @@ 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) +{ + struct hlsl_ir_node *arg; + + if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) + return false; + + return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_LOG2, arg, loc); +} + static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -3300,6 +3311,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