[PATCH vkd3d v2 7/9] vkd3d-shader/hlsl: Store boolean constants as unsigned.

Giovanni Mascellani gmascellani at codeweavers.com
Mon Mar 28 03:59:12 CDT 2022


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>
---
v2:
 * New
---
 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 e4db386f..6b00d117 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -415,7 +415,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 41fa7df4..481347ee 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -842,7 +842,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;
@@ -3394,7 +3394,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 3d0f9e41..c1f5560e 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -1200,7 +1200,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.35.1




More information about the wine-devel mailing list