Zebediah Figura : vkd3d-shader: Store the hlsl_reg_reservation struct directly.

Alexandre Julliard julliard at winehq.org
Fri Jun 18 14:43:57 CDT 2021


Module: vkd3d
Branch: master
Commit: e8e138ed54ba5b3b2348f74adc64ec626ab77245
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=e8e138ed54ba5b3b2348f74adc64ec626ab77245

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Mon May 31 21:41:14 2021 -0500

vkd3d-shader: Store the hlsl_reg_reservation struct directly.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 libs/vkd3d-shader/hlsl.c         |  4 ++--
 libs/vkd3d-shader/hlsl.h         |  2 +-
 libs/vkd3d-shader/hlsl.y         | 44 ++++++++++++++++------------------------
 libs/vkd3d-shader/hlsl_codegen.c |  2 +-
 4 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 441fd6c..e9bfc37 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -95,7 +95,6 @@ void hlsl_free_var(struct hlsl_ir_var *decl)
 {
     vkd3d_free((void *)decl->name);
     vkd3d_free((void *)decl->semantic.name);
-    vkd3d_free((void *)decl->reg_reservation);
     vkd3d_free(decl);
 }
 
@@ -406,7 +405,8 @@ struct hlsl_ir_var *hlsl_new_var(struct hlsl_ctx *ctx, const char *name, struct
     if (semantic)
         var->semantic = *semantic;
     var->modifiers = modifiers;
-    var->reg_reservation = reg_reservation;
+    if (reg_reservation)
+        var->reg_reservation = *reg_reservation;
     return var;
 }
 
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index 906d864..d9e51b8 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -223,7 +223,7 @@ struct hlsl_ir_var
     const char *name;
     struct hlsl_semantic semantic;
     unsigned int modifiers;
-    const struct hlsl_reg_reservation *reg_reservation;
+    struct hlsl_reg_reservation reg_reservation;
     struct list scope_entry, param_entry, extern_entry;
 
     unsigned int first_write, last_read;
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index d8ad1f9..2e631fa 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -33,14 +33,14 @@ struct parse_parameter
     struct hlsl_type *type;
     const char *name;
     struct hlsl_semantic semantic;
-    const struct hlsl_reg_reservation *reg_reservation;
+    struct hlsl_reg_reservation reg_reservation;
     unsigned int modifiers;
 };
 
 struct parse_colon_attribute
 {
     struct hlsl_semantic semantic;
-    struct hlsl_reg_reservation *reg_reservation;
+    struct hlsl_reg_reservation reg_reservation;
 };
 
 struct parse_initializer
@@ -64,7 +64,7 @@ struct parse_variable_def
     char *name;
     struct parse_array_sizes arrays;
     struct hlsl_semantic semantic;
-    struct hlsl_reg_reservation *reg_reservation;
+    struct hlsl_reg_reservation reg_reservation;
     struct parse_initializer initializer;
 };
 
@@ -767,7 +767,7 @@ static bool add_func_parameter(struct hlsl_ctx *ctx, struct list *list,
         hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER,
                 "Parameter '%s' is declared as both \"out\" and \"uniform\".", param->name);
 
-    if (!(var = hlsl_new_var(ctx, param->name, param->type, loc, &param->semantic, param->modifiers, param->reg_reservation)))
+    if (!(var = hlsl_new_var(ctx, param->name, param->type, loc, &param->semantic, param->modifiers, &param->reg_reservation)))
         return false;
     var->is_param = 1;
 
@@ -780,22 +780,17 @@ static bool add_func_parameter(struct hlsl_ctx *ctx, struct list *list,
     return true;
 }
 
-static struct hlsl_reg_reservation *parse_reg_reservation(struct hlsl_ctx *ctx, const char *reg_string)
+static struct hlsl_reg_reservation parse_reg_reservation(const char *reg_string)
 {
-    struct hlsl_reg_reservation *reg_res;
-    DWORD regnum = 0;
+    struct hlsl_reg_reservation reservation = {0};
 
-    if (!sscanf(reg_string + 1, "%u", &regnum))
+    if (!sscanf(reg_string + 1, "%u", &reservation.regnum))
     {
         FIXME("Unsupported register reservation syntax.\n");
-        return NULL;
+        return reservation;
     }
-
-    if (!(reg_res = hlsl_alloc(ctx, sizeof(*reg_res))))
-        return NULL;
-    reg_res->type = reg_string[0];
-    reg_res->regnum = regnum;
-    return reg_res;
+    reservation.type = reg_string[0];
+    return reservation;
 }
 
 static const struct hlsl_ir_function_decl *get_overloaded_func(struct rb_tree *funcs, char *name,
@@ -1354,7 +1349,6 @@ static void free_parse_variable_def(struct parse_variable_def *v)
     vkd3d_free(v->arrays.sizes);
     vkd3d_free(v->name);
     vkd3d_free((void *)v->semantic.name);
-    vkd3d_free(v->reg_reservation);
     vkd3d_free(v);
 }
 
@@ -1393,7 +1387,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
         if (type->type != HLSL_CLASS_MATRIX)
             check_invalid_matrix_modifiers(ctx, modifiers, v->loc);
 
-        if (!(var = hlsl_new_var(ctx, v->name, type, v->loc, &v->semantic, modifiers, v->reg_reservation)))
+        if (!(var = hlsl_new_var(ctx, v->name, type, v->loc, &v->semantic, modifiers, &v->reg_reservation)))
         {
             free_parse_variable_def(v);
             continue;
@@ -1564,7 +1558,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
     struct parse_if_body if_body;
     enum parse_unary_op unary_op;
     enum parse_assign_op assign_op;
-    struct hlsl_reg_reservation *reg_reservation;
+    struct hlsl_reg_reservation reg_reservation;
     struct parse_colon_attribute colon_attribute;
     struct hlsl_semantic semantic;
 }
@@ -1962,11 +1956,9 @@ func_prototype:
                         "Semantics are not allowed on void functions.");
             }
 
-            if ($7.reg_reservation)
-            {
+            if ($7.reg_reservation.type)
                 FIXME("Unexpected register reservation for a function.\n");
-                vkd3d_free($7.reg_reservation);
-            }
+
             if (!($$.decl = hlsl_new_func_decl(ctx, $2, $5, &$7.semantic, @3)))
                 YYABORT;
             $$.name = $3;
@@ -1999,12 +1991,12 @@ colon_attribute:
       %empty
         {
             $$.semantic.name = NULL;
-            $$.reg_reservation = NULL;
+            $$.reg_reservation.type = 0;
         }
     | semantic
         {
             $$.semantic = $1;
-            $$.reg_reservation = NULL;
+            $$.reg_reservation.type = 0;
         }
     | register_opt
         {
@@ -2028,7 +2020,7 @@ semantic:
 register_opt:
       ':' KW_REGISTER '(' any_identifier ')'
         {
-            $$ = parse_reg_reservation(ctx, $4);
+            $$ = parse_reg_reservation($4);
             vkd3d_free($4);
         }
     | ':' KW_REGISTER '(' any_identifier ',' any_identifier ')'
@@ -2036,7 +2028,7 @@ register_opt:
             FIXME("Ignoring shader target %s in a register reservation.\n", debugstr_a($4));
             vkd3d_free($4);
 
-            $$ = parse_reg_reservation(ctx, $6);
+            $$ = parse_reg_reservation($6);
             vkd3d_free($6);
         }
 
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index 3b1b19c..366b8bd 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -35,7 +35,7 @@ static void prepend_uniform_copy(struct hlsl_ctx *ctx, struct list *instrs, stru
     /* Use the synthetic name for the temp, rather than the uniform, so that we
      * can write the uniform name into the shader reflection data. */
 
-    if (!(uniform = hlsl_new_var(ctx, temp->name, temp->data_type, temp->loc, NULL, 0, temp->reg_reservation)))
+    if (!(uniform = hlsl_new_var(ctx, temp->name, temp->data_type, temp->loc, NULL, 0, &temp->reg_reservation)))
         return;
     list_add_before(&temp->scope_entry, &uniform->scope_entry);
     list_add_tail(&ctx->extern_vars, &uniform->extern_entry);




More information about the wine-cvs mailing list