[PATCH vkd3d v4 1/2] vkd3d-shader/hlsl: Add round intrinsic function and test.
Zebediah Figura
zfigura at codeweavers.com
Thu Nov 18 11:35:48 CST 2021
From: Francisco Casas <fcasas at codeweavers.com>
Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
v4: Move intrinsic_round() to be alphabetized with the other functions.
Makefile.am | 1 +
libs/vkd3d-shader/hlsl.c | 1 +
libs/vkd3d-shader/hlsl.h | 1 +
libs/vkd3d-shader/hlsl.y | 8 ++++++++
libs/vkd3d-shader/hlsl_sm4.c | 4 ++++
tests/round.shader_test | 26 ++++++++++++++++++++++++++
6 files changed, 41 insertions(+)
create mode 100644 tests/round.shader_test
diff --git a/Makefile.am b/Makefile.am
index 3186cdbf0..915174422 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -90,6 +90,7 @@ vkd3d_shader_tests = \
tests/preproc-invalid.shader_test \
tests/preproc-macro.shader_test \
tests/preproc-misc.shader_test \
+ tests/round.shader_test \
tests/sampler.shader_test \
tests/saturate.shader_test \
tests/swizzle-0.shader_test \
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 1eee4278a..9824c56dc 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -1156,6 +1156,7 @@ const char *debug_hlsl_expr_op(enum hlsl_ir_expr_op op)
[HLSL_OP1_NEG] = "-",
[HLSL_OP1_NRM] = "nrm",
[HLSL_OP1_RCP] = "rcp",
+ [HLSL_OP1_ROUND] = "round",
[HLSL_OP1_RSQ] = "rsq",
[HLSL_OP1_SAT] = "sat",
[HLSL_OP1_SIGN] = "sign",
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index f2a7a48d5..04f86cdd6 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -299,6 +299,7 @@ enum hlsl_ir_expr_op
HLSL_OP1_NEG,
HLSL_OP1_NRM,
HLSL_OP1_RCP,
+ HLSL_OP1_ROUND,
HLSL_OP1_RSQ,
HLSL_OP1_SAT,
HLSL_OP1_SIGN,
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index b7e0409da..abf5da916 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -1611,6 +1611,12 @@ static bool intrinsic_pow(struct hlsl_ctx *ctx,
return true;
}
+static bool intrinsic_round(struct hlsl_ctx *ctx,
+ const struct parse_initializer *params, struct vkd3d_shader_location loc)
+{
+ return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_ROUND, params->args[0], &loc);
+}
+
static bool intrinsic_saturate(struct hlsl_ctx *ctx,
const struct parse_initializer *params, struct vkd3d_shader_location loc)
{
@@ -1626,10 +1632,12 @@ static const struct intrinsic_function
}
intrinsic_functions[] =
{
+ /* Note: these entries should be kept in alphabetical order. */
{"abs", 1, true, intrinsic_abs},
{"clamp", 3, true, intrinsic_clamp},
{"max", 2, true, intrinsic_max},
{"pow", 2, true, intrinsic_pow},
+ {"round", 1, true, intrinsic_round},
{"saturate", 1, true, intrinsic_saturate},
};
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c
index 413f33651..cd237efe5 100644
--- a/libs/vkd3d-shader/hlsl_sm4.c
+++ b/libs/vkd3d-shader/hlsl_sm4.c
@@ -1341,6 +1341,10 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV, &expr->node, arg1, VKD3D_SM4_REGISTER_MODIFIER_NEGATE);
break;
+ case HLSL_OP1_ROUND:
+ write_sm4_unary_op(buffer, VKD3D_SM4_OP_ROUND_NE, &expr->node, arg1, 0);
+ break;
+
case HLSL_OP1_SAT:
write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV
| (VKD3D_SM4_INSTRUCTION_FLAG_SATURATE << VKD3D_SM4_INSTRUCTION_FLAGS_SHIFT),
diff --git a/tests/round.shader_test b/tests/round.shader_test
new file mode 100644
index 000000000..d8eb11b77
--- /dev/null
+++ b/tests/round.shader_test
@@ -0,0 +1,26 @@
+[pixel shader]
+float4 main(uniform float4 u) : sv_target
+{
+ return round(u);
+}
+
+[test]
+uniform 0 float4 -0.5 6.5 7.5 3.4
+draw quad
+probe all rgba (0.0, 6.0, 8.0, 3.0) 4
+
+
+
+[pixel shader]
+float4 main(uniform float4 u) : sv_target
+{
+ float a = round(u.r);
+ int2 b = round(u.gb);
+ float4 res = float4(b, a, u.a);
+ return round(res);
+}
+
+[test]
+uniform 0 float4 -0.5 6.5 7.5 3.4
+draw quad
+probe all rgba (6.0, 8.0, 0.0, 3.0) 4
--
2.33.1
More information about the wine-devel
mailing list