Nikolay Sivov : vkd3d-shader/hlsl: Cast round() input to float.
Alexandre Julliard
julliard at winehq.org
Wed Feb 2 16:35:20 CST 2022
Module: vkd3d
Branch: master
Commit: 22d8b0a03307659c46c1d3a801566b0305f6da7f
URL: https://source.winehq.org/git/vkd3d.git/?a=commit;h=22d8b0a03307659c46c1d3a801566b0305f6da7f
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Wed Feb 2 13:46:13 2022 +0100
vkd3d-shader/hlsl: Cast round() input to float.
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>
---
libs/vkd3d-shader/hlsl.y | 19 ++++++++++++++++++-
tests/round.shader_test | 13 +++++++++++++
tests/shader_runner.c | 8 ++++++++
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index be24a74..8d7b124 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -1570,6 +1570,18 @@ static const struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *c
return args.decl;
}
+static struct hlsl_ir_node *intrinsic_float_convert_arg(struct hlsl_ctx *ctx,
+ const struct parse_initializer *params, struct hlsl_ir_node *arg, const struct vkd3d_shader_location *loc)
+{
+ struct hlsl_type *type = arg->data_type;
+
+ if (type->base_type == HLSL_TYPE_FLOAT || type->base_type == HLSL_TYPE_HALF)
+ return arg;
+
+ type = hlsl_get_numeric_type(ctx, type->type, HLSL_TYPE_FLOAT, type->dimx, type->dimy);
+ return add_implicit_conversion(ctx, params->instrs, arg, type, loc);
+}
+
static bool intrinsic_abs(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
@@ -1675,7 +1687,12 @@ static bool intrinsic_pow(struct hlsl_ctx *ctx,
static bool intrinsic_round(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
- return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_ROUND, params->args[0], 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_ROUND, arg, loc);
}
static bool intrinsic_saturate(struct hlsl_ctx *ctx,
diff --git a/tests/round.shader_test b/tests/round.shader_test
index d8eb11b..cc5a697 100644
--- a/tests/round.shader_test
+++ b/tests/round.shader_test
@@ -24,3 +24,16 @@ float4 main(uniform float4 u) : sv_target
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
+
+
+
+[pixel shader]
+float4 main(uniform int4 u) : sv_target
+{
+ return round(u);
+}
+
+[test]
+uniform 0 int4 -1 0 2 10
+draw quad
+probe all rgba (-1.0, 0.0, 2.0, 10.0) 4
diff --git a/tests/shader_runner.c b/tests/shader_runner.c
index 5af4628..558d074 100644
--- a/tests/shader_runner.c
+++ b/tests/shader_runner.c
@@ -368,6 +368,14 @@ static void parse_test_directive(struct shader_context *context, const char *lin
fatal_error("Malformed float constant '%s'.\n", line);
set_uniforms(context, offset, 1, &f);
}
+ else if (match_string(line, "int4", &line))
+ {
+ int v[4];
+
+ if (sscanf(line, "%d %d %d %d", &v[0], &v[1], &v[2], &v[3]) < 4)
+ fatal_error("Malformed int4 constant '%s'.\n", line);
+ set_uniforms(context, offset, 4, v);
+ }
else if (match_string(line, "int", &line))
{
int i;
More information about the wine-cvs
mailing list