vkd3d-shader/hlsl: Apply latent majority modifiers to typedefs as well.

This commit is contained in:
Zebediah Figura
2022-03-29 19:15:40 -05:00
committed by Alexandre Julliard
parent 322963add8
commit 5838364886
Notes: Alexandre Julliard 2023-02-28 22:10:58 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Francisco Casas (@fcasas)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/102
2 changed files with 29 additions and 29 deletions

View File

@@ -877,7 +877,7 @@ static const struct hlsl_struct_field *get_struct_field(const struct hlsl_struct
} }
static struct hlsl_type *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_type *type, static struct hlsl_type *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_type *type,
unsigned int *modifiers, struct vkd3d_shader_location loc) unsigned int *modifiers, bool force_majority, const struct vkd3d_shader_location *loc)
{ {
unsigned int default_majority = 0; unsigned int default_majority = 0;
struct hlsl_type *new_type; struct hlsl_type *new_type;
@@ -886,12 +886,12 @@ static struct hlsl_type *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_
&& !(type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK) && !(type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK)
&& type->type == HLSL_CLASS_MATRIX) && type->type == HLSL_CLASS_MATRIX)
{ {
if (!(default_majority = ctx->matrix_majority)) if (!(default_majority = ctx->matrix_majority) && force_majority)
default_majority = HLSL_MODIFIER_COLUMN_MAJOR; default_majority = HLSL_MODIFIER_COLUMN_MAJOR;
} }
else if (type->type != HLSL_CLASS_MATRIX) else if (type->type != HLSL_CLASS_MATRIX)
{ {
check_invalid_matrix_modifiers(ctx, *modifiers, loc); check_invalid_matrix_modifiers(ctx, *modifiers, *loc);
} }
if (!default_majority && !(*modifiers & HLSL_TYPE_MODIFIERS_MASK)) if (!default_majority && !(*modifiers & HLSL_TYPE_MODIFIERS_MASK))
@@ -903,7 +903,7 @@ static struct hlsl_type *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_
*modifiers &= ~HLSL_TYPE_MODIFIERS_MASK; *modifiers &= ~HLSL_TYPE_MODIFIERS_MASK;
if ((new_type->modifiers & HLSL_MODIFIER_ROW_MAJOR) && (new_type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR)) if ((new_type->modifiers & HLSL_MODIFIER_ROW_MAJOR) && (new_type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR))
hlsl_error(ctx, &loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER,
"'row_major' and 'column_major' modifiers are mutually exclusive."); "'row_major' and 'column_major' modifiers are mutually exclusive.");
return new_type; return new_type;
@@ -995,8 +995,7 @@ static bool gen_struct_fields(struct hlsl_ctx *ctx, struct parse_fields *fields,
return true; return true;
} }
static bool add_typedef(struct hlsl_ctx *ctx, const unsigned int modifiers, static bool add_typedef(struct hlsl_ctx *ctx, struct hlsl_type *const orig_type, struct list *list)
struct hlsl_type *const orig_type, struct list *list)
{ {
struct parse_variable_def *v, *v_next; struct parse_variable_def *v, *v_next;
struct hlsl_type *type; struct hlsl_type *type;
@@ -1007,22 +1006,17 @@ static bool add_typedef(struct hlsl_ctx *ctx, const unsigned int modifiers,
{ {
if (!v->arrays.count) if (!v->arrays.count)
{ {
/* Do not use apply_type_modifiers() here. We should not apply the if (!(type = hlsl_type_clone(ctx, orig_type, 0, 0)))
* latent matrix majority to plain matrix types. */
if (!(type = hlsl_type_clone(ctx, orig_type, 0, modifiers)))
{ {
free_parse_variable_def(v); free_parse_variable_def(v);
continue; continue;
} }
if (type->type != HLSL_CLASS_MATRIX)
check_invalid_matrix_modifiers(ctx, modifiers, v->loc);
} }
else else
{ {
unsigned int var_modifiers = modifiers; unsigned int var_modifiers = 0;
if (!(type = apply_type_modifiers(ctx, orig_type, &var_modifiers, v->loc))) if (!(type = apply_type_modifiers(ctx, orig_type, &var_modifiers, true, &v->loc)))
{ {
free_parse_variable_def(v); free_parse_variable_def(v);
continue; continue;
@@ -1052,11 +1046,6 @@ static bool add_typedef(struct hlsl_ctx *ctx, const unsigned int modifiers,
vkd3d_free((void *)type->name); vkd3d_free((void *)type->name);
type->name = v->name; type->name = v->name;
if ((type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR)
&& (type->modifiers & HLSL_MODIFIER_ROW_MAJOR))
hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER,
"'row_major' and 'column_major' modifiers are mutually exclusive.");
ret = hlsl_scope_add_type(ctx->cur_scope, type); ret = hlsl_scope_add_type(ctx->cur_scope, type);
if (!ret) if (!ret)
hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED, hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED,
@@ -4065,7 +4054,7 @@ struct_declaration:
"Modifiers are not allowed on struct type declarations."); "Modifiers are not allowed on struct type declarations.");
} }
if (!(type = apply_type_modifiers(ctx, $2, &modifiers, @1))) if (!(type = apply_type_modifiers(ctx, $2, &modifiers, true, &@1)))
YYABORT; YYABORT;
$$ = declare_vars(ctx, type, modifiers, &@1, $3); $$ = declare_vars(ctx, type, modifiers, &@1, $3);
} }
@@ -4150,7 +4139,7 @@ field:
struct hlsl_type *type; struct hlsl_type *type;
unsigned int modifiers = $1; unsigned int modifiers = $1;
if (!(type = apply_type_modifiers(ctx, $2, &modifiers, @1))) if (!(type = apply_type_modifiers(ctx, $2, &modifiers, true, &@1)))
YYABORT; YYABORT;
if (modifiers & ~HLSL_STORAGE_NOINTERPOLATION) if (modifiers & ~HLSL_STORAGE_NOINTERPOLATION)
{ {
@@ -4300,7 +4289,7 @@ func_prototype_no_attrs:
if (modifiers & ~HLSL_MODIFIERS_MAJORITY_MASK) if (modifiers & ~HLSL_MODIFIERS_MAJORITY_MASK)
hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER,
"Only majority modifiers are allowed on functions."); "Only majority modifiers are allowed on functions.");
if (!(type = apply_type_modifiers(ctx, $2, &modifiers, @1))) if (!(type = apply_type_modifiers(ctx, $2, &modifiers, true, &@1)))
YYABORT; YYABORT;
if ((var = hlsl_get_var(ctx->globals, $3))) if ((var = hlsl_get_var(ctx->globals, $3)))
{ {
@@ -4526,7 +4515,7 @@ parameter:
struct hlsl_type *type; struct hlsl_type *type;
unsigned int i; unsigned int i;
if (!(type = apply_type_modifiers(ctx, $2, &modifiers, @1))) if (!(type = apply_type_modifiers(ctx, $2, &modifiers, true, &@1)))
YYABORT; YYABORT;
$$.modifiers = modifiers; $$.modifiers = modifiers;
@@ -4758,9 +4747,20 @@ typedef_type:
typedef: typedef:
KW_TYPEDEF var_modifiers typedef_type type_specs ';' KW_TYPEDEF var_modifiers typedef_type type_specs ';'
{ {
if ($2 & ~HLSL_TYPE_MODIFIERS_MASK) struct parse_variable_def *v, *v_next;
unsigned int modifiers = $2;
struct hlsl_type *type;
if (!(type = apply_type_modifiers(ctx, $3, &modifiers, false, &@2)))
{
LIST_FOR_EACH_ENTRY_SAFE(v, v_next, $4, struct parse_variable_def, entry)
free_parse_variable_def(v);
vkd3d_free($4);
YYABORT;
}
if (modifiers)
{ {
struct parse_variable_def *v, *v_next;
hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER,
"Storage modifiers are not allowed on typedefs."); "Storage modifiers are not allowed on typedefs.");
LIST_FOR_EACH_ENTRY_SAFE(v, v_next, $4, struct parse_variable_def, entry) LIST_FOR_EACH_ENTRY_SAFE(v, v_next, $4, struct parse_variable_def, entry)
@@ -4768,7 +4768,7 @@ typedef:
vkd3d_free($4); vkd3d_free($4);
YYABORT; YYABORT;
} }
if (!add_typedef(ctx, $2, $3, $4)) if (!add_typedef(ctx, type, $4))
YYABORT; YYABORT;
} }
@@ -4800,7 +4800,7 @@ declaration:
struct hlsl_type *type; struct hlsl_type *type;
unsigned int modifiers = $1; unsigned int modifiers = $1;
if (!(type = apply_type_modifiers(ctx, $2, &modifiers, @1))) if (!(type = apply_type_modifiers(ctx, $2, &modifiers, true, &@1)))
YYABORT; YYABORT;
$$ = declare_vars(ctx, type, modifiers, &@1, $3); $$ = declare_vars(ctx, type, modifiers, &@1, $3);
} }

View File

@@ -112,12 +112,12 @@ float4 main() : sv_target
uniform 0 float4 0.1 0.2 0.0 0.0 uniform 0 float4 0.1 0.2 0.0 0.0
uniform 4 float4 0.3 0.4 0.0 0.0 uniform 4 float4 0.3 0.4 0.0 0.0
draw quad draw quad
todo probe all rgba (0.1, 0.2, 0.3, 0.4) probe all rgba (0.1, 0.2, 0.3, 0.4)
% In fact, it's illegal to specify a contradictory majority. % In fact, it's illegal to specify a contradictory majority.
[pixel shader fail todo] [pixel shader fail]
#pragma pack_matrix(row_major) #pragma pack_matrix(row_major)
typedef float2x2 mat_t; typedef float2x2 mat_t;
uniform column_major mat_t m; uniform column_major mat_t m;