Commit 5f18f9f7 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

d3dcompiler: Calculate the register size of types.

parent f82b4474
......@@ -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, unsigned int default_majority) 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;
......
......@@ -720,6 +720,13 @@ static BOOL add_struct_field(struct list *fields, struct hlsl_struct_field *fiel
return TRUE;
}
BOOL is_row_major(const struct hlsl_type *type)
{
/* Default to column-major if the majority isn't explicitly set, which can
* happen for anonymous nodes. */
return !!(type->modifiers & HLSL_MODIFIER_ROW_MAJOR);
}
static struct hlsl_type *apply_type_modifiers(struct hlsl_type *type,
unsigned int *modifiers, struct source_location loc)
{
......@@ -750,6 +757,9 @@ static struct hlsl_type *apply_type_modifiers(struct hlsl_type *type,
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;
}
......@@ -798,6 +808,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)
{
......@@ -809,6 +821,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;
......@@ -837,6 +856,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;
if ((type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR)
&& (type->modifiers & HLSL_MODIFIER_ROW_MAJOR))
......
......@@ -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;
}
......@@ -960,8 +965,13 @@ struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_ma
case HLSL_CLASS_ARRAY:
type->e.array.type = clone_hlsl_type(old->e.array.type, default_majority);
type->e.array.elements_count = old->e.array.elements_count;
type->reg_size = type->e.array.elements_count * type->e.array.type->reg_size;
break;
case HLSL_CLASS_STRUCT:
{
unsigned int reg_size = 0;
type->e.elements = d3dcompiler_alloc(sizeof(*type->e.elements));
if (!type->e.elements)
{
......@@ -991,10 +1001,20 @@ struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_ma
if (old_field->semantic)
field->semantic = d3dcompiler_strdup(old_field->semantic);
field->modifiers = old_field->modifiers;
field->reg_offset = reg_size;
reg_size += field->type->reg_size;
list_add_tail(type->e.elements, &field->entry);
}
type->reg_size = reg_size;
break;
}
case HLSL_CLASS_MATRIX:
type->reg_size = is_row_major(type) ? type->dimy : type->dimx;
break;
default:
type->reg_size = 1;
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment