From c680b674d61aac3dbe72a5286793f61bbf873423 Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Fri, 22 Apr 2022 12:24:57 +0200 Subject: [PATCH] vkd3d-shader/hlsl: Do not generate infinities in SM1. Signed-off-by: Giovanni Mascellani Signed-off-by: Henri Verbeet Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard --- libs/vkd3d-shader/hlsl_constant_ops.c | 9 ++++++++- tests/arithmetic-float.shader_test | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 06b957ba..a1551ba1 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ +#include + #include "hlsl.h" static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, struct hlsl_ir_constant *src) @@ -270,12 +272,17 @@ static bool fold_div(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, { case HLSL_TYPE_FLOAT: case HLSL_TYPE_HALF: - if (src2->value[k].f == 0) + if (ctx->profile->major_version >= 4 && src2->value[k].f == 0) { hlsl_warning(ctx, &dst->node.loc, VKD3D_SHADER_WARNING_HLSL_DIVISION_BY_ZERO, "Floating point division by zero"); } dst->value[k].f = src1->value[k].f / src2->value[k].f; + if (ctx->profile->major_version < 4 && isinf(dst->value[k].f)) + { + hlsl_error(ctx, &dst->node.loc, VKD3D_SHADER_ERROR_HLSL_DIVISION_BY_ZERO, + "Infinities are not allowed by the shader model."); + } break; case HLSL_TYPE_DOUBLE: diff --git a/tests/arithmetic-float.shader_test b/tests/arithmetic-float.shader_test index f99b9728..6824c3f1 100644 --- a/tests/arithmetic-float.shader_test +++ b/tests/arithmetic-float.shader_test @@ -25,6 +25,7 @@ todo draw quad probe all rgba (5.0, 5.0, -5.0, 3.0) [require] +% Infinities are not allowed in SM1 shader model >= 4.0 [pixel shader]