Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ValveSoftware/vkd3d.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZebediah Figura <zfigura@codeweavers.com>2022-04-14 02:52:16 +0300
committerGiovanni Mascellani <gmascellani@codeweavers.com>2022-07-26 15:48:55 +0300
commit90071a06720142c2cce5f4fb9a43306e35b1909d (patch)
tree95fec9ea9f8499eefbf48d156a03cde4ca684f7e
parenteff2eb148b1cabb112def88ca6523ba6372f8f22 (diff)
vkd3d-shader/hlsl: Handle out-of-bounds and special values when converting float to uint.
[Why are the other tests broken? My guess is the driver is broken...]
-rw-r--r--libs/vkd3d-shader/hlsl_constant_ops.c14
-rw-r--r--tests/cast-to-uint.shader_test2
2 files changed, 13 insertions, 3 deletions
diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c
index a7e0ef0a..62f835bb 100644
--- a/libs/vkd3d-shader/hlsl_constant_ops.c
+++ b/libs/vkd3d-shader/hlsl_constant_ops.c
@@ -21,6 +21,16 @@
#include <math.h>
#include "hlsl.h"
+#include <math.h>
+
+static uint32_t double_to_uint(double d)
+{
+ if (isnan(d) || d < 0)
+ return 0;
+ if (d > UINT_MAX)
+ return UINT_MAX;
+ return d;
+}
static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, struct hlsl_ir_constant *src)
{
@@ -44,14 +54,14 @@ static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, struct
{
case HLSL_TYPE_FLOAT:
case HLSL_TYPE_HALF:
- u = src->value[k].f;
+ u = double_to_uint(src->value[k].f);
i = src->value[k].f;
f = src->value[k].f;
d = src->value[k].f;
break;
case HLSL_TYPE_DOUBLE:
- u = src->value[k].d;
+ u = double_to_uint(src->value[k].d);
i = src->value[k].d;
f = src->value[k].d;
d = src->value[k].d;
diff --git a/tests/cast-to-uint.shader_test b/tests/cast-to-uint.shader_test
index 7fee8551..8e6027cc 100644
--- a/tests/cast-to-uint.shader_test
+++ b/tests/cast-to-uint.shader_test
@@ -42,7 +42,7 @@ float4 main() : sv_target
[test]
draw quad
-todo probe all rgba (0.5, 0.5, 0.5, 0.5)
+probe all rgba (0.5, 0.5, 0.5, 0.5)
% Large values are clamped.