Nikolay Sivov : vkd3d-shader/hlsl: Implement floor().

Alexandre Julliard julliard at winehq.org
Wed Feb 2 16:35:20 CST 2022


Module: vkd3d
Branch: master
Commit: 4e36c1825d25654b330f0a8bd12a5d2b2645a93f
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=4e36c1825d25654b330f0a8bd12a5d2b2645a93f

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Wed Feb  2 13:46:15 2022 +0100

vkd3d-shader/hlsl: Implement floor().

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 Makefile.am                  |  1 +
 libs/vkd3d-shader/hlsl.h     |  1 +
 libs/vkd3d-shader/hlsl.y     | 12 ++++++++++++
 libs/vkd3d-shader/hlsl_sm4.c |  4 ++++
 tests/floor.shader_test      | 38 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 56 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 82807a4..5bcee67 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -57,6 +57,7 @@ vkd3d_shader_tests = \
 	tests/cast-to-int.shader_test \
 	tests/cast-to-uint.shader_test \
 	tests/conditional.shader_test \
+	tests/floor.shader_test \
 	tests/hlsl-array-dimension.shader_test \
 	tests/hlsl-bool-cast.shader_test \
 	tests/hlsl-clamp.shader_test \
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index 2319895..5b69186 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -293,6 +293,7 @@ enum hlsl_ir_expr_op
     HLSL_OP1_DSX,
     HLSL_OP1_DSY,
     HLSL_OP1_EXP2,
+    HLSL_OP1_FLOOR,
     HLSL_OP1_FRACT,
     HLSL_OP1_LOG2,
     HLSL_OP1_LOGIC_NOT,
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index dd2a93e..5b98b56 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -1653,6 +1653,17 @@ static bool intrinsic_cross(struct hlsl_ctx *ctx,
     return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, &mul2->node, mul1_neg, loc);
 }
 
+static bool intrinsic_floor(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_FLOOR, arg, loc);
+}
+
 static bool intrinsic_max(struct hlsl_ctx *ctx,
         const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
 {
@@ -1720,6 +1731,7 @@ intrinsic_functions[] =
     {"abs",                                 1, true,  intrinsic_abs},
     {"clamp",                               3, true,  intrinsic_clamp},
     {"cross",                               2, true,  intrinsic_cross},
+    {"floor",                               1, true,  intrinsic_floor},
     {"max",                                 2, true,  intrinsic_max},
     {"min",                                 2, true,  intrinsic_min},
     {"pow",                                 2, true,  intrinsic_pow},
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c
index 4eebd58..b66a225 100644
--- a/libs/vkd3d-shader/hlsl_sm4.c
+++ b/libs/vkd3d-shader/hlsl_sm4.c
@@ -1432,6 +1432,10 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
                     write_sm4_unary_op(buffer, VKD3D_SM4_OP_EXP, &expr->node, arg1, 0);
                     break;
 
+                case HLSL_OP1_FLOOR:
+                    write_sm4_unary_op(buffer, VKD3D_SM4_OP_ROUND_NI, &expr->node, arg1, 0);
+                    break;
+
                 case HLSL_OP1_LOG2:
                     write_sm4_unary_op(buffer, VKD3D_SM4_OP_LOG, &expr->node, arg1, 0);
                     break;
diff --git a/tests/floor.shader_test b/tests/floor.shader_test
new file mode 100644
index 0000000..033d759
--- /dev/null
+++ b/tests/floor.shader_test
@@ -0,0 +1,38 @@
+[pixel shader]
+float4 main(uniform float4 u) : sv_target
+{
+    return floor(u);
+}
+
+[test]
+uniform 0 float4 -0.5 6.5 7.5 3.4
+draw quad
+probe all rgba (-1.0, 6.0, 7.0, 3.0) 4
+
+[pixel shader]
+float4 main(uniform float4 u) : sv_target
+{
+    float a = floor(u.r);
+    int2 b = floor(u.gb);
+    float4 res = float4(b, a, u.a);
+    return floor(res);
+}
+
+[test]
+uniform 0 float4 -0.5 6.5 7.5 3.4
+draw quad
+probe all rgba (6.0, 7.0, -1.0, 3.0) 4
+
+[pixel shader]
+float4 main(uniform int4 u) : sv_target
+{
+    float a = floor(u.r);
+    int2 b = floor(u.gb);
+    float4 res = float4(b, a, u.a);
+    return floor(res);
+}
+
+[test]
+uniform 0 int4 -1 6 7 3
+draw quad
+probe all rgba (6.0, 7.0, -1.0, 3.0) 4




More information about the wine-cvs mailing list