[PATCH vkd3d 3/6] vkd3d-shader: Use separate flag fields to track whether a variable is a uniform or varying.

Zebediah Figura zfigura at codeweavers.com
Mon Mar 22 17:02:37 CDT 2021


Mostly in order to make it clearer that these don't directly correspond to the
modifiers with which the variable was declared.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 libs/vkd3d-shader/hlsl.c         | 22 ++++++++--------------
 libs/vkd3d-shader/hlsl.h         |  8 +++++---
 libs/vkd3d-shader/hlsl.y         | 32 +++++++++++++++++++++++---------
 libs/vkd3d-shader/hlsl_codegen.c |  4 ++--
 4 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 4526348e..794166dd 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -388,7 +388,7 @@ struct hlsl_ir_expr *hlsl_new_copy(struct hlsl_ir_node *node)
 }
 
 struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const struct vkd3d_shader_location loc,
-        const char *semantic, unsigned int modifiers, const struct hlsl_reg_reservation *reg_reservation)
+        const char *semantic, const struct hlsl_reg_reservation *reg_reservation)
 {
     struct hlsl_ir_var *var;
 
@@ -399,7 +399,6 @@ struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const
     var->data_type = type;
     var->loc = loc;
     var->semantic = semantic;
-    var->modifiers = modifiers;
     var->reg_reservation = reg_reservation;
     return var;
 }
@@ -407,7 +406,7 @@ struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const
 struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type,
         const struct vkd3d_shader_location loc)
 {
-    struct hlsl_ir_var *var = hlsl_new_var(vkd3d_strdup(name), type, loc, NULL, 0, NULL);
+    struct hlsl_ir_var *var = hlsl_new_var(vkd3d_strdup(name), type, loc, NULL, NULL);
 
     if (var)
         list_add_tail(&ctx->globals->vars, &var->scope_entry);
@@ -869,17 +868,12 @@ static void dump_src(struct vkd3d_string_buffer *buffer, const struct hlsl_src *
 
 static void dump_ir_var(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_var *var)
 {
-    if (var->modifiers)
-    {
-        struct vkd3d_string_buffer_cache string_buffers;
-        struct vkd3d_string_buffer *string;
-
-        vkd3d_string_buffer_cache_init(&string_buffers);
-        if ((string = hlsl_modifiers_to_string(&string_buffers, var->modifiers)))
-            vkd3d_string_buffer_printf(buffer, "%s ", string->buffer);
-        vkd3d_string_buffer_release(&string_buffers, string);
-        vkd3d_string_buffer_cache_cleanup(&string_buffers);
-    }
+    if (var->is_input_varying)
+        vkd3d_string_buffer_printf(buffer, "in ");
+    if (var->is_output_varying)
+        vkd3d_string_buffer_printf(buffer, "out ");
+    if (var->is_uniform)
+        vkd3d_string_buffer_printf(buffer, "uniform ");
     vkd3d_string_buffer_printf(buffer, "%s %s", debug_hlsl_type(var->data_type), var->name);
     if (var->semantic)
         vkd3d_string_buffer_printf(buffer, " : %s", var->semantic);
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index 523d156d..cc740eab 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -204,11 +204,14 @@ struct hlsl_ir_var
     struct vkd3d_shader_location loc;
     const char *name;
     const char *semantic;
-    unsigned int modifiers;
     const struct hlsl_reg_reservation *reg_reservation;
     struct list scope_entry, param_entry;
 
     unsigned int first_write, last_read;
+
+    uint32_t is_input_varying : 1;
+    uint32_t is_output_varying : 1;
+    uint32_t is_uniform : 1;
 };
 
 struct hlsl_ir_function
@@ -546,8 +549,7 @@ struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned i
 struct hlsl_ir_node *hlsl_new_unary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg,
         struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
 struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const struct vkd3d_shader_location loc,
-        const char *semantic, unsigned int modifiers,
-        const struct hlsl_reg_reservation *reg_reservation) DECLSPEC_HIDDEN;
+        const char *semantic, const struct hlsl_reg_reservation *reg_reservation) DECLSPEC_HIDDEN;
 struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ir_var *var, const struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
 
 void hlsl_error(struct hlsl_ctx *ctx, const struct vkd3d_shader_location loc, enum vkd3d_shader_error error,
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 41fea19b..912064b2 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -763,9 +763,21 @@ static bool add_func_parameter(struct hlsl_ctx *ctx, struct list *list,
     if (param->type->type == HLSL_CLASS_MATRIX)
         assert(param->type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK);
 
-    if (!(var = hlsl_new_var(param->name, param->type, loc, param->semantic, param->modifiers, param->reg_reservation)))
+    if (!(var = hlsl_new_var(param->name, param->type, loc, param->semantic, param->reg_reservation)))
         return false;
 
+    if (param->modifiers & HLSL_STORAGE_UNIFORM)
+    {
+        var->is_uniform = 1;
+    }
+    else
+    {
+        if (param->modifiers & HLSL_STORAGE_IN)
+            var->is_input_varying = 1;
+        if (param->modifiers & HLSL_STORAGE_OUT)
+            var->is_output_varying = 1;
+    }
+
     if (!hlsl_add_var(ctx, var, false))
     {
         hlsl_free_var(var);
@@ -1405,18 +1417,20 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
         for (i = 0; i < v->arrays.count; ++i)
             type = hlsl_new_array_type(ctx, type, v->arrays.sizes[i]);
 
-        if (!(var = hlsl_new_var(v->name, type, v->loc, v->semantic, modifiers, v->reg_reservation)))
+        if (type->type != HLSL_CLASS_MATRIX)
+            check_invalid_matrix_modifiers(ctx, modifiers, v->loc);
+
+        if (!(var = hlsl_new_var(v->name, type, v->loc, v->semantic, v->reg_reservation)))
         {
             free_parse_variable_def(v);
             continue;
         }
 
-        if (var->data_type->type != HLSL_CLASS_MATRIX)
-            check_invalid_matrix_modifiers(ctx, var->modifiers, var->loc);
-
         if (ctx->cur_scope == ctx->globals)
         {
-            var->modifiers |= HLSL_STORAGE_UNIFORM;
+            if (!(modifiers & HLSL_STORAGE_STATIC))
+                var->is_uniform = 1;
+
             local = false;
 
             if ((func = hlsl_get_func_decl(ctx, var->name)))
@@ -1432,11 +1446,11 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
             static const unsigned int invalid = HLSL_STORAGE_EXTERN | HLSL_STORAGE_SHARED
                     | HLSL_STORAGE_GROUPSHARED | HLSL_STORAGE_UNIFORM;
 
-            if (var->modifiers & invalid)
+            if (modifiers & invalid)
             {
                 struct vkd3d_string_buffer *string;
 
-                if ((string = hlsl_modifiers_to_string(&ctx->string_buffers, var->modifiers & invalid)))
+                if ((string = hlsl_modifiers_to_string(&ctx->string_buffers, modifiers & invalid)))
                     hlsl_error(ctx, var->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER,
                             "Modifiers '%s' are not allowed on local variables.", string->buffer);
                 vkd3d_string_buffer_release(&ctx->string_buffers, string);
@@ -1447,7 +1461,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
         }
 
         if ((type->modifiers & HLSL_MODIFIER_CONST) && !v->initializer.args_count
-                && !(var->modifiers & (HLSL_STORAGE_STATIC | HLSL_STORAGE_UNIFORM)))
+                && !(modifiers & (HLSL_STORAGE_STATIC | HLSL_STORAGE_UNIFORM)))
         {
             hlsl_error(ctx, v->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_INITIALIZER,
                     "Const variable \"%s\" is missing an initializer.", var->name);
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index b9f753a1..f27714c3 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -403,9 +403,9 @@ static void compute_liveness(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl
 
     LIST_FOR_EACH_ENTRY(var, entry_func->parameters, struct hlsl_ir_var, param_entry)
     {
-        if (var->modifiers & HLSL_STORAGE_IN)
+        if (var->is_input_varying)
             var->first_write = 1;
-        if (var->modifiers & HLSL_STORAGE_OUT)
+        if (var->is_output_varying)
             var->last_read = UINT_MAX;
     }
 
-- 
2.31.0




More information about the wine-devel mailing list