Giovanni Mascellani : vkd3d-shader/hlsl: Fold constant modulus.
Alexandre Julliard
julliard at winehq.org
Fri Apr 15 15:11:02 CDT 2022
Module: vkd3d
Branch: master
Commit: 2b23b7329c484d1b6c0bb37cbefe5b564283b06e
URL: https://source.winehq.org/git/vkd3d.git/?a=commit;h=2b23b7329c484d1b6c0bb37cbefe5b564283b06e
Author: Giovanni Mascellani <gmascellani at codeweavers.com>
Date: Thu Apr 14 12:52:40 2022 +0200
vkd3d-shader/hlsl: Fold constant modulus.
This commit includes work by Francisco Casas.
Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
libs/vkd3d-shader/hlsl_constant_ops.c | 48 +++++++++++++++++++++++++++++++++++
tests/arithmetic-int.shader_test | 11 +++++++-
tests/arithmetic-uint.shader_test | 9 +++++++
3 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c
index 9a8bc6b0..06b957ba 100644
--- a/libs/vkd3d-shader/hlsl_constant_ops.c
+++ b/libs/vkd3d-shader/hlsl_constant_ops.c
@@ -318,6 +318,50 @@ static bool fold_div(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst,
return true;
}
+static bool fold_mod(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst,
+ struct hlsl_ir_constant *src1, struct hlsl_ir_constant *src2)
+{
+ enum hlsl_base_type type = dst->node.data_type->base_type;
+ unsigned int k;
+
+ assert(type == src1->node.data_type->base_type);
+ assert(type == src2->node.data_type->base_type);
+
+ for (k = 0; k < dst->node.data_type->dimx; ++k)
+ {
+ switch (type)
+ {
+ case HLSL_TYPE_INT:
+ if (src2->value[k].i == 0)
+ {
+ hlsl_error(ctx, &dst->node.loc, VKD3D_SHADER_ERROR_HLSL_DIVISION_BY_ZERO,
+ "Division by zero.");
+ return false;
+ }
+ if (src1->value[k].i == INT_MIN && src2->value[k].i == -1)
+ dst->value[k].i = 0;
+ else
+ dst->value[k].i = src1->value[k].i % src2->value[k].i;
+ break;
+
+ case HLSL_TYPE_UINT:
+ if (src2->value[k].u == 0)
+ {
+ hlsl_error(ctx, &dst->node.loc, VKD3D_SHADER_ERROR_HLSL_DIVISION_BY_ZERO,
+ "Division by zero.");
+ return false;
+ }
+ dst->value[k].u = src1->value[k].u % src2->value[k].u;
+ break;
+
+ default:
+ FIXME("Fold modulus for type %s.\n", debug_hlsl_type(ctx, dst->node.data_type));
+ return false;
+ }
+ }
+ return true;
+}
+
bool hlsl_fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct hlsl_ir_constant *arg1, *arg2 = NULL, *res;
@@ -375,6 +419,10 @@ bool hlsl_fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void
success = fold_div(ctx, res, arg1, arg2);
break;
+ case HLSL_OP2_MOD:
+ success = fold_mod(ctx, res, arg1, arg2);
+ break;
+
default:
FIXME("Fold \"%s\" expression.\n", debug_hlsl_expr_op(expr->op));
success = false;
diff --git a/tests/arithmetic-int.shader_test b/tests/arithmetic-int.shader_test
index c85b9a3a..c2eee2ba 100644
--- a/tests/arithmetic-int.shader_test
+++ b/tests/arithmetic-int.shader_test
@@ -21,7 +21,7 @@ float4 main() : SV_TARGET
}
[test]
-todo draw quad
+draw quad
probe all rgba (5.0, 5.0, -5.0, 3.0)
[pixel shader fail]
@@ -32,3 +32,12 @@ float4 main() : SV_TARGET
return x / y;
}
+
+[pixel shader fail]
+float4 main() : SV_TARGET
+{
+ int x = 1;
+ int y = 0;
+
+ return x % y;
+}
diff --git a/tests/arithmetic-uint.shader_test b/tests/arithmetic-uint.shader_test
index f37c881e..f1801b9c 100644
--- a/tests/arithmetic-uint.shader_test
+++ b/tests/arithmetic-uint.shader_test
@@ -35,3 +35,12 @@ float4 main() : SV_TARGET
return x / y;
}
+
+[pixel shader fail]
+float4 main() : SV_TARGET
+{
+ uint x = 1;
+ uint y = 0;
+
+ return x % y;
+}
More information about the wine-cvs
mailing list