[PATCH vkd3d 10/11] vkd3d-shader/hlsl: Store boolean constants as unsigned.
Matteo Bruni
mbruni at codeweavers.com
Tue Apr 5 05:33:12 CDT 2022
From: Giovanni Mascellani <gmascellani at codeweavers.com>
With this change it is possible to store booleans as 0xffffffff,
similarly as what happens at runtime.
Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
Technically that's only true in SM4 (not that you can really expose
the SM1 internal representation).
libs/vkd3d-shader/hlsl.c | 2 +-
libs/vkd3d-shader/hlsl.h | 1 -
libs/vkd3d-shader/hlsl.y | 4 ++--
libs/vkd3d-shader/hlsl_codegen.c | 2 +-
libs/vkd3d-shader/hlsl_constant_ops.c | 20 ++++++++++----------
5 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 664f7813..eabe189f 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -1168,7 +1168,7 @@ static void dump_ir_constant(struct vkd3d_string_buffer *buffer, const struct hl
switch (type->base_type)
{
case HLSL_TYPE_BOOL:
- vkd3d_string_buffer_printf(buffer, "%s ", value->b ? "true" : "false");
+ vkd3d_string_buffer_printf(buffer, "%s ", value->u ? "true" : "false");
break;
case HLSL_TYPE_DOUBLE:
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index b1952320..802adf87 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -416,7 +416,6 @@ struct hlsl_ir_constant
int32_t i;
float f;
double d;
- bool b;
} value[4];
struct hlsl_reg reg;
};
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index fa22e6cd..9918be72 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -867,7 +867,7 @@ static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node)
case HLSL_TYPE_DOUBLE:
return value->d;
case HLSL_TYPE_BOOL:
- return value->b;
+ return !!value->u;
default:
assert(0);
return 0;
@@ -3444,7 +3444,7 @@ primary_expr:
if (!(c = hlsl_alloc(ctx, sizeof(*c))))
YYABORT;
init_node(&c->node, HLSL_IR_CONSTANT, hlsl_get_scalar_type(ctx, HLSL_TYPE_BOOL), @1);
- c->value[0].b = $1;
+ c->value[0].u = $1 ? ~0u : 0;
if (!($$ = make_list(ctx, &c->node)))
YYABORT;
}
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index 881a6d62..2b05264c 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -1205,7 +1205,7 @@ static void allocate_const_registers_recurse(struct hlsl_ctx *ctx, struct hlsl_b
switch (type->base_type)
{
case HLSL_TYPE_BOOL:
- f = value->b;
+ f = !!value->u;
break;
case HLSL_TYPE_FLOAT:
diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c
index 92f5a856..87b5bc90 100644
--- a/libs/vkd3d-shader/hlsl_constant_ops.c
+++ b/libs/vkd3d-shader/hlsl_constant_ops.c
@@ -47,7 +47,7 @@ static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, struct
i = src->value[k].f;
f = src->value[k].f;
d = src->value[k].f;
- b = src->value[k].f;
+ b = !!src->value[k].f;
break;
case HLSL_TYPE_DOUBLE:
@@ -55,7 +55,7 @@ static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, struct
i = src->value[k].d;
f = src->value[k].d;
d = src->value[k].d;
- b = src->value[k].d;
+ b = !!src->value[k].d;
break;
case HLSL_TYPE_INT:
@@ -63,7 +63,7 @@ static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, struct
i = src->value[k].i;
f = src->value[k].i;
d = src->value[k].i;
- b = src->value[k].i;
+ b = !!src->value[k].i;
break;
case HLSL_TYPE_UINT:
@@ -71,15 +71,15 @@ static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, struct
i = src->value[k].u;
f = src->value[k].u;
d = src->value[k].u;
- b = src->value[k].u;
+ b = !!src->value[k].u;
break;
case HLSL_TYPE_BOOL:
- u = src->value[k].b;
- i = src->value[k].b;
- f = src->value[k].b;
- d = src->value[k].b;
- b = src->value[k].b;
+ u = !!src->value[k].u;
+ i = !!src->value[k].u;
+ f = !!src->value[k].u;
+ d = !!src->value[k].u;
+ b = !!src->value[k].u;
break;
default:
@@ -107,7 +107,7 @@ static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, struct
break;
case HLSL_TYPE_BOOL:
- dst->value[k].b = b;
+ dst->value[k].u = b ? ~0u : 0;
break;
default:
--
2.34.1
More information about the wine-devel
mailing list