[PATCH 4/5] d3dcompiler: Calculate the register size of types.

Zebediah Figura z.figura12 at gmail.com
Sun Mar 29 21:53:19 CDT 2020


From: Zebediah Figura <zfigura at codeweavers.com>

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 dlls/d3dcompiler_43/d3dcompiler_private.h |  3 +++
 dlls/d3dcompiler_43/hlsl.y                | 23 +++++++++++++++++++++++
 dlls/d3dcompiler_43/utils.c               |  9 +++++++++
 3 files changed, 35 insertions(+)

diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h
index df45a7082fe..4fdb464a4ef 100644
--- a/dlls/d3dcompiler_43/d3dcompiler_private.h
+++ b/dlls/d3dcompiler_43/d3dcompiler_private.h
@@ -614,6 +614,7 @@ struct hlsl_type
     unsigned int modifiers;
     unsigned int dimx;
     unsigned int dimy;
+    unsigned int reg_size;
     union
     {
         struct list *elements;
@@ -632,6 +633,7 @@ struct hlsl_struct_field
     const char *name;
     const char *semantic;
     DWORD modifiers;
+    unsigned int reg_offset;
 };
 
 struct source_location
@@ -1083,6 +1085,7 @@ struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_clas
 struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int array_size) DECLSPEC_HIDDEN;
 struct hlsl_type *clone_hlsl_type(struct hlsl_type *old) DECLSPEC_HIDDEN;
 struct hlsl_type *get_type(struct hlsl_scope *scope, const char *name, BOOL recursive) DECLSPEC_HIDDEN;
+BOOL is_row_major(const struct hlsl_type *type) DECLSPEC_HIDDEN;
 BOOL find_function(const char *name) DECLSPEC_HIDDEN;
 unsigned int components_count_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
 BOOL compare_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2) DECLSPEC_HIDDEN;
diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y
index 312949c5840..d6c64edcace 100644
--- a/dlls/d3dcompiler_43/hlsl.y
+++ b/dlls/d3dcompiler_43/hlsl.y
@@ -717,6 +717,15 @@ static BOOL add_struct_field(struct list *fields, struct hlsl_struct_field *fiel
     return TRUE;
 }
 
+BOOL is_row_major(const struct hlsl_type *type)
+{
+    if (type->modifiers & HLSL_MODIFIER_ROW_MAJOR)
+        return TRUE;
+    if (type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR)
+        return FALSE;
+    return hlsl_ctx.matrix_majority == HLSL_ROW_MAJOR;
+}
+
 static struct hlsl_type *apply_type_modifiers(struct hlsl_type *type, DWORD *modifiers, struct source_location loc)
 {
     struct hlsl_type *new_type;
@@ -729,6 +738,9 @@ static struct hlsl_type *apply_type_modifiers(struct hlsl_type *type, DWORD *mod
 
     new_type->modifiers = add_modifiers(new_type->modifiers, *modifiers, loc);
     *modifiers &= ~HLSL_TYPE_MODIFIERS_MASK;
+
+    if (new_type->type == HLSL_CLASS_MATRIX)
+        new_type->reg_size = is_row_major(new_type) ? new_type->dimy : new_type->dimx;
     return new_type;
 }
 
@@ -774,6 +786,8 @@ static struct list *gen_struct_fields(struct hlsl_type *type, DWORD modifiers, s
 static struct hlsl_type *new_struct_type(const char *name, struct list *fields)
 {
     struct hlsl_type *type = d3dcompiler_alloc(sizeof(*type));
+    struct hlsl_struct_field *field;
+    unsigned int reg_size = 0;
 
     if (!type)
     {
@@ -785,6 +799,13 @@ static struct hlsl_type *new_struct_type(const char *name, struct list *fields)
     type->dimx = type->dimy = 1;
     type->e.elements = fields;
 
+    LIST_FOR_EACH_ENTRY(field, fields, struct hlsl_struct_field, entry)
+    {
+        field->reg_offset = reg_size;
+        reg_size += field->type->reg_size;
+    }
+    type->reg_size = reg_size;
+
     list_add_tail(&hlsl_ctx.types, &type->entry);
 
     return type;
@@ -813,6 +834,8 @@ static BOOL add_typedef(DWORD modifiers, struct hlsl_type *orig_type, struct lis
 
         if (type->type != HLSL_CLASS_MATRIX)
             check_invalid_matrix_modifiers(type->modifiers, v->loc);
+        else
+            type->reg_size = is_row_major(type) ? type->dimy : type->dimx;
 
         ret = add_type_to_scope(hlsl_ctx.cur_scope, type);
         if (!ret)
diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c
index 84323c334f8..94f7ee59e75 100644
--- a/dlls/d3dcompiler_43/utils.c
+++ b/dlls/d3dcompiler_43/utils.c
@@ -820,6 +820,10 @@ struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_clas
     type->base_type = base_type;
     type->dimx = dimx;
     type->dimy = dimy;
+    if (type_class == HLSL_CLASS_MATRIX)
+        type->reg_size = is_row_major(type) ? dimy : dimx;
+    else
+        type->reg_size = 1;
 
     list_add_tail(&hlsl_ctx.types, &type->entry);
 
@@ -836,6 +840,7 @@ struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int arra
     type->modifiers = basic_type->modifiers;
     type->e.array.elements_count = array_size;
     type->e.array.type = basic_type;
+    type->reg_size = basic_type->reg_size * array_size;
     return type;
 }
 
@@ -953,6 +958,7 @@ struct hlsl_type *clone_hlsl_type(struct hlsl_type *old)
     type->dimy = old->dimy;
     type->modifiers = old->modifiers;
     type->sampler_dim = old->sampler_dim;
+    type->reg_size = old->reg_size;
     switch (old->type)
     {
         case HLSL_CLASS_ARRAY:
@@ -989,6 +995,9 @@ struct hlsl_type *clone_hlsl_type(struct hlsl_type *old)
                 if (old_field->semantic)
                     field->semantic = d3dcompiler_strdup(old_field->semantic);
                 field->modifiers = old_field->modifiers;
+                /* Fix up the reg_size if we added a majority modifier. */
+                if (field->type->type == HLSL_CLASS_MATRIX)
+                    field->type->reg_size = is_row_major(field->type) ? field->type->dimy : field->type->dimx;
                 list_add_tail(type->e.elements, &field->entry);
             }
             break;
-- 
2.25.1




More information about the wine-devel mailing list